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

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>
            日韩一区二区精品在线观看| 欧美一区二区高清| 亚洲欧美视频一区二区三区| 欧美午夜三级| 亚洲人成高清| 国产性做久久久久久| 亚洲一区免费在线观看| 久久综合中文字幕| 亚洲欧美视频在线观看| 亚洲美女精品成人在线视频| 国产欧美精品| 亚洲欧美乱综合| 亚洲国产精品久久人人爱蜜臀 | 国产精品综合av一区二区国产馆| 国产精品蜜臀在线观看| 国产欧美一区二区白浆黑人| 狠狠久久综合婷婷不卡| 亚洲国产一区二区a毛片| 一区二区三区www| 久久成人精品无人区| 欧美chengren| 亚洲一区二区三区精品在线观看| 久久精品在线| 国产精品mv在线观看| 伊人成年综合电影网| 国产精品99久久久久久人| 久久久久久久久伊人| 亚洲久久一区二区| 久久久久久精| 国产精品一区二区久久| 亚洲精品字幕| 老司机精品久久| 亚洲日本黄色| 中文av字幕一区| 亚洲欧美日韩爽爽影院| 尤物精品在线| 亚洲欧美在线一区| 亚洲第一久久影院| 欧美一级大片在线免费观看| 欧美日韩成人一区二区三区| 精品福利免费观看| 午夜亚洲福利| 一本色道久久综合亚洲精品小说 | 亚洲国产经典视频| 亚洲制服av| 亚洲国产精品女人久久久| 国产精品视频区| 亚洲精选久久| 久久久久国色av免费观看性色| 亚洲国产精品视频| 999在线观看精品免费不卡网站| 久久激情五月丁香伊人| 欧美日韩一卡二卡| 99热精品在线| 一区二区三区欧美在线观看| 亚洲欧美韩国| 亚洲视频一区在线观看| 欧美精品免费看| 日韩午夜在线播放| 亚洲国产精品一区二区第四页av | 日韩视频免费| 最新高清无码专区| 美女久久网站| 亚洲精品中文字幕有码专区| 亚洲国产精品999| 欧美精品三级在线观看| 亚洲免费精品| 一本色道久久综合狠狠躁的推荐| 欧美日韩国产在线| 亚洲字幕一区二区| 午夜精品区一区二区三| 国内成人在线| 欧美电影电视剧在线观看| 免费日韩av片| 亚洲午夜精品| 欧美一区二区三区免费观看视频| 91久久久精品| 最新成人av网站| 欧美日韩一二三四五区| 亚洲免费视频一区二区| 午夜精品久久久久久久男人的天堂| 国产日韩三区| 欧美激情中文字幕在线| 欧美日韩网址| 久久久久国产一区二区| 美女图片一区二区| 亚洲欧美变态国产另类| 久久激情婷婷| 日韩视频免费看| 亚洲在线一区二区| 精品av久久707| av成人毛片| 伊人久久久大香线蕉综合直播| 91久久精品视频| 国产亚洲a∨片在线观看| 亚洲黄色影片| 狠狠色狠狠色综合日日91app| 最新成人在线| 好看不卡的中文字幕| 亚洲伦理精品| 永久91嫩草亚洲精品人人| 亚洲精品视频免费观看| 国产一区二区三区四区在线观看| 亚洲第一精品电影| 国产日产欧产精品推荐色| 亚洲高清资源| 国产亚洲激情| 中日韩男男gay无套 | 悠悠资源网亚洲青| 亚洲特级毛片| 亚洲精品日韩精品| 久久精品国产69国产精品亚洲| 亚洲精品一区二区三区av| 午夜久久福利| 亚洲免费一区二区| 欧美另类一区二区三区| 久热爱精品视频线路一| 国产精品美女久久久浪潮软件| 欧美激情精品久久久久久大尺度| 国产精品日韩在线观看| 99成人精品| 一区二区三区产品免费精品久久75| 欧美影院一区| 欧美在线首页| 国产精品一区二区你懂的| 一区二区三区免费在线观看| 亚洲精品美女在线| 免费影视亚洲| 亚洲丰满少妇videoshd| 精品1区2区3区4区| 久久久激情视频| 久久久无码精品亚洲日韩按摩| 欧美三级小说| 99国产精品私拍| 亚洲一区二区在线视频| 国产精品户外野外| 一本色道久久综合精品竹菊| 亚洲视频电影图片偷拍一区| 欧美国产日韩一二三区| 亚洲国产精品激情在线观看| 欧美亚洲一区二区在线观看| 老司机久久99久久精品播放免费 | 亚洲第一在线| 一区二区在线视频播放| 欧美影院成人| 老司机精品导航| 亚洲大片av| 欧美+亚洲+精品+三区| 欧美激情久久久久| 亚洲精品国产精品久久清纯直播| 欧美顶级少妇做爰| 亚洲精品久久| 亚洲免费在线| 狠狠色综合网| 欧美大片91| 亚洲神马久久| 久久野战av| 亚洲精品一区二区三区在线观看| 欧美人与性禽动交情品 | 亚洲美女在线一区| 欧美日韩一区二区三区在线视频| 一二美女精品欧洲| 久久成人免费网| 亚洲电影天堂av| 欧美日韩一区综合| 欧美在线亚洲在线| 亚洲高清自拍| 亚洲欧美偷拍卡通变态| 好吊日精品视频| 欧美激情亚洲一区| 亚洲综合电影| 免费在线播放第一区高清av| 亚洲精品视频免费观看| 国产精品久久久久久久免费软件| 午夜亚洲精品| 亚洲美女中出| 老妇喷水一区二区三区| 亚洲美女福利视频网站| 国产酒店精品激情| 你懂的网址国产 欧美| 亚洲自拍偷拍视频| 亚洲国产精品一区二区www在线 | 香蕉成人伊视频在线观看| 激情久久一区| 国产精品久久久爽爽爽麻豆色哟哟| 欧美伊久线香蕉线新在线| 亚洲国内在线| 久久夜色精品国产亚洲aⅴ| 99视频精品全部免费在线| 狠狠色2019综合网| 国产精品扒开腿爽爽爽视频| 久久久久久国产精品mv| 亚洲天堂成人在线观看| 亚洲高清在线| 欧美粗暴jizz性欧美20| 久久久99国产精品免费| 亚洲资源av| 亚洲深夜激情| 一本一本大道香蕉久在线精品| 亚洲国产精品一区二区久 |