青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

The Way of C++

  C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
  55 Posts :: 0 Stories :: 19 Comments :: 0 Trackbacks

公告

The first time i use this blog, i will write something that i learn which i think is worth write down.

常用鏈接

留言簿(3)

我參與的團隊

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

    Forgive my ugly English description ,and i may it will help you. -_-
    (Reference by : http://www.cplusplus.com/reference/iostream/istream/getline.html)
    the function prototype is as follows:
    istream& getline (char* s, streamsize n );
    istream& getline (char* s, streamsize n, char delim );
    
    the function extracts charatcters from the input sequence and stores them as c-tring into the array begin at s. Characters are extracted until either n-1 characters have been extracted or the delimiting character is found.( the char delim can be specified by yourself, or be '\n' by default). Remember this, when the delimiter is found ,it will be extracted and discarded, i.e, it is extracted from the input stream and not stored to the s , and the next input operation will begin after this extracted delimiter. ). After the data extracted ,the ending null charactor ('\0') will be appended to s automatically.
    The following is same examples.
    
 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     char fruit[100];
 6     cin.getline(fruit,100,'*');
 7     cout<<fruit<<endl;
 8     
 9     system("pause");
10 }
11 
    
    now ,when you input "banana apple pear\n"( here \n means the enter), then the console will show "banana apple pear"
   
   also ,you can specify the delimiter by yourself  as this.
  
 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     char fruit[100];
 6     cin.getline(fruit,100,'*');
 7     cout<<fruit<<endl;
 8     
 9     system("pause");
10 }
11 
    now,when you input "banana apple pear * orange\n",then the console will show " banana apple pera" , here the orange is not readed because is is after the delimiter '*'.
    
    So simple about use this function ,right ? now see this example .
    
 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     char fruit[100];
 6     while(cin.getline(fruit,100,'*'))
 7     {
 8         cout<<fruit<<endl;
 9     }
10     
11     system("pause");
12 }
13 
  Here we want to input number of lines ,each of line is delimited by a '*'.
  In the first time : we input " banana apple *\n" then the console show "banana apple" ,this is right.
  But the problem comes, in the second input " pear orange *\n", now the console show "\n(\n means a blank line) pear orange". Here a blank line will be output, betray to our will that showing "pear orange";
   The problem is that a '\n' is stored in the fruit in the second time as the first element, i.e, the fruit is "\npear orange\0" in the second input. In the first getline ,it extracted the input stream until the first '*' was found, then it discarded the '*', but the following character is '\n' which you input in the first time, this '\n' is still in the input stream. And the second getline read the stream form this '\n'. As we know ,the delimiter is specified as '*' ,so the '\n' is not a delimiter here ,and it will be stored into the second fruit. 
   How to resovle this problem ? In order to avoid the situation above ,we can use the get to extract the '\n' character. And now it work normally.
  
 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     char fruit[100];
 6     while(cin.getline(fruit,100,'*'))
 7     {
 8         cin.get();
 9         cout<<fruit<<endl;
10     }
11     
12     system("pause");
13 }
14 
   
   One thing you have to remember is that this is a function of the cin.
   there is also a global function getline() in the heder <string>. But you must use string object as parameter instead of c-string.  See the following example. 
   (Reference to :http://www.cplusplus.com/reference/string/getline.html)
  
 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 int main()
 5 {
 6     string s;
 7     getline(cin,s,'*');
 8     cout<<s<<endl;
 9     system("pause");
10 }
11 
    As you can see, the first parameter is istream object on which the extraction operation is performed. The second parameter str is the string object where the extracted content is stored. The Third parameter delim is the delimiting character. The operation of extracting succesive characters is stopped when this delimeter is read. And it will be etracted and discarded. 
   
   
  
  


   
    
    
  
posted on 2007-12-26 17:55 koson 閱讀(1080) 評論(3)  編輯 收藏 引用 所屬分類: C/C++

Feedback

# re: About the use of getline() 2007-12-27 12:21 夢在天涯
good , where are you in ?
your english is good!
  回復  更多評論
  

# re: About the use of getline()[未登錄] 2007-12-27 12:28 Koson
thx, i'm in guangzhou. Actually, i write this using the reference of the website. But i think this may be a way to improve the written english , despite the content is as simple as that. -_-  回復  更多評論
  

# re: About the use of getline()[未登錄] 2007-12-27 14:00 jarod
..... where are u in ?..................

should be

where are u..........  回復  更多評論
  


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            中文一区二区| 欧美亚洲三级| 国产麻豆一精品一av一免费| 久久久久这里只有精品| 欧美在线视频在线播放完整版免费观看 | 国产又爽又黄的激情精品视频| 欧美国产1区2区| 老司机精品视频一区二区三区| 久久精品青青大伊人av| 久久美女性网| 欧美视频不卡| 在线观看精品一区| 一区二区福利| 欧美在线啊v一区| 欧美激情精品久久久久久| 亚洲免费av片| 久久综合五月| 国产日韩精品一区| 99人久久精品视频最新地址| 欧美一区二区在线免费播放| 欧美激情中文字幕一区二区| 亚洲小视频在线| 欧美精品在线观看播放| 在线看无码的免费网站| 欧美怡红院视频一区二区三区| 亚洲国产精品电影在线观看| 91久久香蕉国产日韩欧美9色| 99re6热只有精品免费观看| 久久精品一区二区三区不卡| 欧美日韩亚洲三区| 亚洲国产精品va在看黑人| 久久精彩免费视频| 亚洲图片欧洲图片日韩av| 欧美韩国日本一区| 亚洲精品视频在线观看网站| 国产亚洲精品bt天堂精选| 一区二区三区你懂的| 亚洲国产成人精品久久久国产成人一区| 午夜国产精品视频| 欧美综合77777色婷婷| 亚洲私拍自拍| 国产乱码精品| 毛片一区二区三区| 欧美freesex8一10精品| 最新中文字幕一区二区三区| 欧美aa在线视频| 欧美日韩成人网| 久久久91精品国产一区二区三区| 欧美亚洲在线| 亚洲精品在线观看免费| 亚洲乱码国产乱码精品精可以看| 欧美日韩激情小视频| 欧美在线一二三| 欧美99在线视频观看| 欧美亚洲三区| 久久伊伊香蕉| 亚洲女性裸体视频| 久久在线免费视频| 亚洲欧美日韩视频一区| 美女黄毛**国产精品啪啪| 中日韩午夜理伦电影免费| 亚洲欧美综合| 亚洲视频在线一区观看| 久久成人免费视频| 欧美一区二区高清| 欧美日韩午夜在线| 麻豆91精品| 国产亚洲永久域名| 亚洲一区二区四区| 亚洲一区二区三区在线播放| 欧美成人一区二区三区片免费| 国产精品永久| 99精品热视频只有精品10| 在线精品国精品国产尤物884a| 夜夜嗨av一区二区三区| 亚洲欧洲精品一区二区精品久久久 | 欧美高清视频一区二区三区在线观看 | 91久久精品久久国产性色也91| 亚洲另类在线一区| 99国产精品视频免费观看一公开 | 久久久精品五月天| 久久人人97超碰国产公开结果| 国产精品极品美女粉嫩高清在线| 最新中文字幕亚洲| 一区二区三区视频在线看| 国产精品成人免费| 亚洲欧美怡红院| 欧美www视频在线观看| 亚洲免费av观看| 欧美无乱码久久久免费午夜一区| 亚洲毛片在线| 久久精品亚洲乱码伦伦中文| 国产主播喷水一区二区| 猛干欧美女孩| 一区二区三区欧美| 你懂的成人av| 午夜精品美女久久久久av福利| 好看的av在线不卡观看| 免费观看成人网| 亚洲午夜久久久久久久久电影院| 欧美电影在线观看| 亚洲午夜精品福利| 牛牛影视久久网| 亚洲一区二区在线观看视频| 好看的日韩视频| 国产精品卡一卡二卡三| 欧美激情欧美狂野欧美精品| 小嫩嫩精品导航| 中文在线资源观看网站视频免费不卡 | 亚洲免费高清| 亚洲国产精品t66y| 欧美成人午夜影院| 久久久久久久久久久一区| 香蕉久久夜色精品国产| 亚洲在线免费| 亚洲一区二区三区国产| 日韩一级大片| 在线观看视频一区| 在线成人av.com| 日韩午夜精品| 午夜在线视频一区二区区别| 亚洲一区二区三区高清| 一区二区成人精品| 欧美一二三区精品| 欧美一区二区精美| 久久久亚洲国产美女国产盗摄| 欧美一区午夜视频在线观看| 欧美亚洲视频一区二区| 鲁大师影院一区二区三区| 久久福利资源站| 欧美www视频在线观看| 亚洲第一在线综合在线| 欧美黄在线观看| 一本到12不卡视频在线dvd| 一本色道久久综合亚洲精品不| 91久久嫩草影院一区二区| 欧美国产激情二区三区| 日韩一级精品视频在线观看| 9色国产精品| 媚黑女一区二区| 欧美激情一区二区三区| 国产精品美女在线| 在线观看免费视频综合| 亚洲女同在线| 亚洲精品欧美| 欧美福利专区| 亚洲第一精品在线| 久久天天狠狠| 午夜精品久久久久久| 欧美视频在线播放| 999在线观看精品免费不卡网站| 久久精品国产亚洲a| 在线亚洲高清视频| 欧美日韩日韩| 亚洲无限av看| 亚洲午夜精品久久久久久app| 欧美成人精品高清在线播放| 国内精品久久久久久| 久久精品免费播放| 欧美中文字幕精品| 国产一区在线播放| 久久躁狠狠躁夜夜爽| 亚洲欧美另类国产| 国产欧美日韩综合精品二区| 亚洲免费黄色| 亚洲级视频在线观看免费1级| 麻豆av福利av久久av| 在线观看成人小视频| 免费看亚洲片| 欧美激情综合| 99国内精品| 亚洲欧美日韩一区二区三区在线观看| 欧美午夜一区二区三区免费大片| 一区二区精品| 午夜精品国产精品大乳美女| 亚洲成人在线| 一区二区精品国产| 伊人成人开心激情综合网| 日韩午夜在线播放| 在线观看中文字幕不卡| 中日韩美女免费视频网址在线观看| 国产亚洲成精品久久| 亚洲理论在线| 欧美亚洲三级| 亚洲欧美综合一区| 欧美日韩成人在线播放| 免费观看成人鲁鲁鲁鲁鲁视频| 欧美日韩中文在线观看| 亚洲高清视频一区| 91久久香蕉国产日韩欧美9色| 久久黄色小说| 久久午夜精品| 在线播放豆国产99亚洲| 久久人人97超碰国产公开结果 | 亚洲精品乱码视频| 久久亚洲美女| 亚洲第一精品影视| 一本一道久久综合狠狠老精东影业| 亚洲男人的天堂在线| 亚洲欧美日韩天堂|