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

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 閱讀(1075) 評論(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..........  回復  更多評論
  

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲第一在线| 有码中文亚洲精品| 亚洲尤物在线视频观看| 一个色综合导航| 国产精品青草综合久久久久99| 欧美一级理论性理论a| 香蕉久久夜色精品国产使用方法| 国产日韩一区二区| 欧美激情视频在线免费观看 欧美视频免费一 | 国产区在线观看成人精品| 性感少妇一区| 久久婷婷国产综合尤物精品| 99精品视频免费观看| 在线中文字幕一区| 依依成人综合视频| 日韩亚洲视频在线| 狠狠色狠狠色综合日日小说| 亚洲精品1区2区| 国产精品盗摄久久久| 久久青草欧美一区二区三区| 欧美人与禽猛交乱配| 久久精品中文字幕一区| 可以免费看不卡的av网站| 在线亚洲免费| 久久精品网址| 亚洲综合色视频| 欧美91福利在线观看| 午夜精品福利视频| 欧美不卡在线视频| 久久久成人网| 国产精品va在线播放我和闺蜜| 久久躁日日躁aaaaxxxx| 欧美视频一区二区三区在线观看| 久久综合久久美利坚合众国| 欧美日本一区二区高清播放视频| 久久五月激情| 国产欧美日韩免费看aⅴ视频| 亚洲乱码国产乱码精品精天堂| 国产一区二区欧美日韩| av不卡在线| 日韩视频免费观看高清完整版| 午夜精品久久一牛影视| 日韩亚洲欧美一区二区三区| 久久精品国产99| 亚洲永久精品国产| 欧美激情一区二区三区在线视频| 久久亚洲欧美| 国产日韩欧美制服另类| 一区二区三区欧美成人| 在线日本成人| 久久久精品一区| 久久久精品一品道一区| 国产精品视频一二| 亚洲视频二区| 中文日韩电影网站| 欧美破处大片在线视频| 91久久一区二区| 亚洲国产精品专区久久| 久久久久久久精| 美日韩丰满少妇在线观看| 韩国v欧美v日本v亚洲v| 久久精品中文字幕免费mv| 午夜国产一区| 国产欧美一区二区在线观看| 一区二区三区精品在线| 亚洲午夜国产一区99re久久 | 一本色道久久综合亚洲精品不卡| 一本色道久久加勒比精品| 久久久久国产一区二区三区四区 | 亚洲综合不卡| 国产精品v欧美精品v日韩精品| 99视频在线观看一区三区| 一区二区三区欧美成人| 国产精品久久久对白| 亚洲专区一区| 久久久久九九九| 在线观看国产精品淫| 麻豆av一区二区三区| 亚洲精品国产系列| 午夜精品福利在线| 国色天香一区二区| 欧美大片免费观看| 在线综合亚洲欧美在线视频| 欧美一区免费视频| 在线看片一区| 欧美性jizz18性欧美| 性18欧美另类| 亚洲国产美女精品久久久久∴| 亚洲视屏在线播放| 韩国一区二区在线观看| 欧美激情网站在线观看| 亚洲综合视频网| 欧美国产日产韩国视频| 亚洲欧美日韩视频二区| 国产欧美在线看| 欧美乱人伦中文字幕在线| 午夜视频在线观看一区二区| 欧美超级免费视 在线| 亚洲视频中文字幕| 国产真实乱偷精品视频免| 欧美激情一区二区久久久| 亚洲欧美久久久| 亚洲国产欧美在线人成| 久久久www成人免费毛片麻豆 | 中文在线一区| 在线免费不卡视频| 国产精品无码专区在线观看| 欧美夫妇交换俱乐部在线观看| 亚洲综合色网站| 亚洲人成网站精品片在线观看| 久久久久88色偷偷免费| 亚洲无线视频| 亚洲精品一区二区三区在线观看 | 国产欧美高清| 欧美性猛片xxxx免费看久爱 | 亚洲欧美日韩视频一区| 亚洲精品护士| 免费在线亚洲| 久久黄金**| 亚洲欧美中文日韩在线| 99国产精品| 亚洲国语精品自产拍在线观看| 国产色综合网| 国产乱码精品| 国产精品伦理| 欧美性大战久久久久久久蜜臀| 美女日韩欧美| 久久亚洲色图| 狂野欧美一区| 欧美在线观看视频在线 | 国产女优一区| 国产精品视频免费一区| 欧美日韩一级视频| 欧美精品久久久久久久| 美女网站在线免费欧美精品| 久久久夜夜夜| 老司机免费视频久久| 久久久夜精品| 免费不卡在线视频| 葵司免费一区二区三区四区五区| 久久久久99精品国产片| 久久成人精品无人区| 欧美伊人久久| 久久精品视频网| 久久亚洲欧美| 欧美激情综合在线| 欧美日韩情趣电影| 国产精品国码视频| 国产精品尤物| 激情自拍一区| 亚洲日本国产| 99视频有精品| 欧美一区二区三区精品电影| 久久精品在线播放| 欧美韩国一区| 亚洲人成人一区二区在线观看| 99精品免费网| 欧美一级网站| 欧美成在线视频| 欧美午夜a级限制福利片| 国产精品久久97| 韩国av一区二区| 亚洲精品在线观看视频| 亚洲一区二区三区四区五区午夜| 香蕉亚洲视频| 欧美激情一级片一区二区| 亚洲美女在线观看| 欧美一区成人| 欧美激情一区二区三区成人| 国产精品影片在线观看| 亚洲电影免费| 亚洲欧美另类在线观看| 理论片一区二区在线| 亚洲精品久久嫩草网站秘色| 亚洲欧美日韩精品久久亚洲区| 久久一综合视频| 欧美午夜剧场| 亚洲国产日韩一区| 亚洲欧美日本国产有色| 免费成人黄色片| 亚洲综合另类| 欧美精品日韩三级| 黄色成人av在线| 亚洲一区二区三区激情| 美女亚洲精品| 午夜日韩av| 欧美色道久久88综合亚洲精品| 在线观看不卡| 欧美激情综合色| 伊人春色精品| 欧美在线观看网站| 日韩亚洲欧美高清| 免费在线亚洲| 激情综合视频| 久久国产99| 中文欧美在线视频| 欧美激情在线播放| 亚洲国产精品视频一区| 久久精品人人做人人爽| 一区二区成人精品 |