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

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>
            国产精品一区=区| 日韩一区二区电影网| 久久久精品国产免大香伊| 欧美大片18| 久久精品一区二区三区不卡| 欧美日韩亚洲一区二区三区在线 | 狠狠88综合久久久久综合网| 一区二区三区四区蜜桃| 亚洲国产成人porn| 欧美亚洲自偷自偷| 国产欧美日韩精品在线| 欧美一级一区| 亚洲在线成人| 国产精品网红福利| 午夜精品美女自拍福到在线| 在线亚洲一区观看| 国产精品日韩欧美一区二区三区| 亚洲欧美日韩精品久久| 亚洲无吗在线| 国产午夜精品一区二区三区视频 | 亚洲天堂网在线观看| 亚洲欧洲一级| 欧美视频中文字幕在线| 亚洲专区一区二区三区| 中日韩美女免费视频网站在线观看| 欧美视频免费| 欧美伊人久久久久久久久影院| 亚洲综合色视频| 国内精品一区二区三区| 欧美成人高清| 欧美极品欧美精品欧美视频| 亚洲美女黄网| 一区二区三区欧美| 国产亚洲一区二区三区| 欧美 日韩 国产在线| 欧美电影打屁股sp| 亚洲欧美日产图| 久久精品视频va| 日韩一区二区高清| 亚洲综合二区| 亚洲欧洲综合另类在线| 99在线热播精品免费| 国产日韩精品综合网站| 欧美**字幕| 欧美视频在线观看视频极品| 久久久久久电影| 欧美精品日韩三级| 久久成人免费网| 欧美激情一区二区久久久| 美女国产精品| 欧美freesex交免费视频| 久久躁日日躁aaaaxxxx| 99re国产精品| 欧美一级久久久久久久大片| 亚洲黄色免费网站| 亚洲欧美精品一区| 亚洲乱码精品一二三四区日韩在线| 亚洲一区二区三区成人在线视频精品 | 老司机67194精品线观看| 欧美日韩国产影院| 乱码第一页成人| 欧美香蕉大胸在线视频观看| 久久综合给合久久狠狠色| 欧美日韩国产综合视频在线| 久久五月婷婷丁香社区| 欧美午夜不卡视频| 欧美成人影音| 国产乱码精品1区2区3区| 亚洲国产日韩一级| 国产一区欧美| 亚洲一区亚洲二区| 99人久久精品视频最新地址| 久久久精品视频成人| 亚洲综合色网站| 欧美黄色影院| 欧美激情第一页xxx| 国产一区二区三区四区三区四 | 小嫩嫩精品导航| 亚洲视频999| 欧美精品成人一区二区在线观看 | 久久久久免费视频| 国产精品入口麻豆原神| 日韩网站在线观看| 91久久精品久久国产性色也91| 欧美一区二区网站| 亚洲欧美久久久| 欧美小视频在线| 一区二区三区高清不卡| 日韩视频在线一区二区三区| 蜜桃av一区二区三区| 欧美不卡高清| 亚洲大胆人体视频| 另类天堂视频在线观看| 免费久久精品视频| 伊人久久久大香线蕉综合直播| 欧美一区二区播放| 久久国产精品亚洲va麻豆| 国产精品一区二区欧美| 亚洲女优在线| 久久gogo国模啪啪人体图| 国产精品亚洲一区二区三区在线| 亚洲午夜三级在线| 欧美尤物巨大精品爽| 国产亚洲欧美一区二区三区| 久久福利影视| 欧美国产大片| 亚洲精品中文字幕在线观看| 欧美了一区在线观看| 91久久国产综合久久| 99精品久久免费看蜜臀剧情介绍| 欧美国产亚洲视频| 夜久久久久久| 久久国产精品久久久久久| 国产一区二区三区高清| 久久久久免费观看| 亚洲国产婷婷香蕉久久久久久| 一区二区日韩欧美| 国产精品家教| 久久激情中文| 亚洲人体影院| 欧美一区二区三区精品| 亚洲第一在线综合网站| 欧美日韩国产高清视频| 午夜激情综合网| 欧美激情一二三区| 亚洲在线观看免费视频| 国产日韩精品在线播放| 免费不卡在线观看av| 这里只有精品在线播放| 鲁大师影院一区二区三区| 一本色道久久88综合亚洲精品ⅰ| 国产精品区一区二区三区| 久久青草欧美一区二区三区| 99精品国产在热久久婷婷| 久久这里有精品视频| 亚洲午夜av在线| 国模 一区 二区 三区| 欧美日韩成人免费| 久久久99久久精品女同性 | 欧美色视频在线| 欧美有码在线视频| 亚洲精品视频在线| 蜜月aⅴ免费一区二区三区| 一区二区三区久久久| 国产午夜精品在线| 欧美日韩专区在线| 欧美不卡视频| 欧美在线视频全部完| 99国产精品久久久久久久久久| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲一级高清| 亚洲日本理论电影| 黄色影院成人| 国产欧美日韩一区二区三区在线观看| 欧美国产在线视频| 久久久精品动漫| 香蕉久久夜色精品国产使用方法| 日韩视频在线一区二区| 欧美成人影音| 久久综合九色欧美综合狠狠| 亚洲欧美日韩国产另类专区| 亚洲破处大片| 亚洲成人在线网| 国产一区在线视频| 国产免费一区二区三区香蕉精| 欧美国产一区二区在线观看| 久久久久9999亚洲精品| 欧美一级淫片aaaaaaa视频| 中文国产一区| 夜夜嗨av一区二区三区中文字幕| 亚洲经典在线| 亚洲国产成人精品久久久国产成人一区| 久久成人18免费观看| 久久成人免费视频| 久久久国产精品亚洲一区| 午夜日韩激情| 欧美一级网站| 久久精品国产欧美激情| 欧美在线播放高清精品| 欧美一区二区精品久久911| 午夜精品久久久久久久久久久| 国产精品视频久久一区| 欧美精品久久久久久久久久| 亚洲深爱激情| 一区二区成人精品| 在线中文字幕一区| 亚洲一区二区三区国产| 一区二区三区欧美在线| 亚洲视频一区二区在线观看| 亚洲小说春色综合另类电影| 亚洲一区二区在线视频| 午夜在线一区| 久久久久一区二区三区| 久久久人成影片一区二区三区观看 | 欧美三级网址| 国产精品一区在线观看| 国产一区二区三区最好精华液| 国产一区视频观看| 亚洲欧洲精品一区二区| 一区二区三区国产精华|