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

The Way of C++

  C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
  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)

我參與的團(tuán)隊(duì)

搜索

  •  

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

    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) 評(píng)論(3)  編輯 收藏 引用 所屬分類: C/C++

Feedback

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

# re: About the use of getline()[未登錄](méi) 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. -_-  回復(fù)  更多評(píng)論
  

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

should be

where are u..........  回復(fù)  更多評(píng)論
  

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            夜夜嗨一区二区| 久久午夜视频| 鲁鲁狠狠狠7777一区二区| 亚洲淫片在线视频| 午夜精品久久久久影视 | 亚洲专区欧美专区| 亚洲欧美日韩一区| 久久全球大尺度高清视频| 欧美成人免费播放| 国产欧亚日韩视频| 亚洲一区二区三区乱码aⅴ| 制服丝袜激情欧洲亚洲| 亚洲一区二区三区视频| 久久精品成人一区二区三区| 久久久久久久97| 欧美国产一区二区| 国产精品亚洲精品| 亚洲品质自拍| 先锋资源久久| 亚洲国产精彩中文乱码av在线播放| 欧美激情精品久久久久久久变态 | 久久久久久电影| 欧美精品日本| 国产午夜亚洲精品理论片色戒| 在线日本成人| 欧美一区二区三区日韩视频| 欧美国产一区二区三区激情无套| 一区二区三区久久网| 欧美在线日韩在线| 欧美视频免费| 亚洲精品久久久久久久久久久| 亚洲永久视频| 亚洲国产裸拍裸体视频在线观看乱了中文 | 亚洲国产成人精品久久久国产成人一区 | 性久久久久久| 亚洲激情在线播放| 久久精品一区二区三区中文字幕| 欧美女主播在线| 精品福利免费观看| 午夜精品国产更新| 亚洲欧洲一区二区三区| 久久久免费观看视频| 国产精品成人一区二区三区吃奶| 亚洲欧洲精品一区二区三区 | 亚洲乱码国产乱码精品精可以看| 久久爱www久久做| 这里只有精品视频在线| 欧美激情亚洲激情| 亚洲国产视频直播| 免费精品99久久国产综合精品| 亚洲在线视频一区| 国产精品久久久久久久久免费桃花 | 欧美日韩久久精品| 欧美在线视频观看免费网站| 欧美日韩第一区| 亚洲人成人一区二区三区| 久久九九99视频| 欧美一区二区高清| 国产欧美一区二区精品性色| 亚洲一区二区三区四区视频| 亚洲欧洲日产国产综合网| 欧美成人午夜激情在线| 最新亚洲激情| 亚洲啪啪91| 欧美日韩调教| 亚洲在线中文字幕| 亚洲婷婷在线| 国产日韩在线一区| 久久久久在线观看| 久久综合九色欧美综合狠狠| 精品盗摄一区二区三区| 玖玖综合伊人| 免费国产自线拍一欧美视频| 亚洲精品一区二区三区樱花 | 亚洲精品欧洲| 日韩一级大片| 国产欧美一区二区三区沐欲| 久久深夜福利| 蜜桃av噜噜一区| 一区二区三区视频在线播放| 一区二区三区视频在线观看| 国产农村妇女精品| 美女主播一区| 欧美日韩在线播放一区| 欧美一区二区精品久久911| 欧美在线视频全部完| 亚洲电影自拍| 一本色道88久久加勒比精品| 国产欧美在线播放| 亚洲国产高清高潮精品美女| 欧美丝袜第一区| 久久资源av| 欧美日韩亚洲综合在线| 久久久久五月天| 欧美日韩免费在线视频| 欧美在线短视频| 免费的成人av| 久久国产88| 欧美日韩成人综合| 欧美aaaaaaaa牛牛影院| 国产精品福利片| 免费成人高清视频| 国产精品久久福利| 亚洲福利视频网| 国产精品视频xxxx| 亚洲国产精品va在看黑人| 国产精品老牛| 亚洲人午夜精品| 樱桃视频在线观看一区| 制服丝袜激情欧洲亚洲| 亚洲欧洲精品一区| 久久精品国产亚洲精品| 亚洲欧美在线磁力| 美国三级日本三级久久99| 亚洲经典视频在线观看| 国产欧美日韩在线| 日韩视频中午一区| 91久久亚洲| 久久午夜av| 久久精品夜夜夜夜久久| 国产精品美女午夜av| 亚洲清纯自拍| 亚洲欧洲在线看| 久久精品视频一| 久久狠狠婷婷| 国产免费成人在线视频| 一片黄亚洲嫩模| 亚洲美女黄网| 欧美精品v国产精品v日韩精品| 免费成人毛片| 怡红院精品视频| 久久久精品国产免费观看同学| 欧美一区二区私人影院日本| 国产精品区一区二区三区| 99精品久久| 亚洲一区视频| 国产精品乱码| 亚洲欧美精品suv| 午夜精品福利在线观看| 国产精品系列在线| 香蕉成人伊视频在线观看| 久久精品1区| 狠狠色2019综合网| 久久影视三级福利片| 欧美第十八页| 一本一本久久a久久精品综合妖精 一本一本久久a久久精品综合麻豆 | 最新日韩av| 免费视频一区| 亚洲精品久久视频| 亚洲一区3d动漫同人无遮挡| 欧美午夜无遮挡| 亚洲欧美成人在线| 理论片一区二区在线| 亚洲国产视频a| 欧美日韩国产成人| 亚洲一区免费视频| 狼人天天伊人久久| 亚洲精品视频一区| 国产精品卡一卡二卡三| 欧美在线视频免费| 亚洲经典自拍| 欧美一区二区三区免费大片| 狠狠色综合播放一区二区| 欧美激情2020午夜免费观看| 一本色道久久综合狠狠躁的推荐| 欧美中文字幕精品| 亚洲激情啪啪| 国产精品久久久久毛片软件| 久久成人这里只有精品| 亚洲国产成人av在线| 午夜精品久久久| 亚洲欧洲综合| 国产精品伊人日日| 欧美国产先锋| 久久高清国产| 亚洲精品免费在线观看| 久久成人国产| 中文国产成人精品| 在线电影一区| 国产精品区一区二区三| 国产欧美精品一区| 欧美成人午夜激情| 午夜国产精品视频| 亚洲高清三级视频| 久久精彩视频| 亚洲一区二区三区四区视频| 亚洲国产你懂的| 国产精品一区二区久久精品| 欧美高清视频在线观看| 久久精品99国产精品| 正在播放日韩| 亚洲人成网站999久久久综合| 久久久久久九九九九| 亚洲一区二区三区欧美| 亚洲开发第一视频在线播放| 一区在线影院| 国产亚洲福利| 国产精品欧美日韩一区| 欧美日韩国产小视频在线观看| 久久一区二区三区超碰国产精品 |