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

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| 欧美午夜精品久久久久免费视| 久久亚洲国产成人| 亚洲男人的天堂在线| 亚洲影视综合| 亚洲男人第一av网站| 亚洲欧美国产精品桃花| 一本色道久久综合亚洲精品按摩| 亚洲日本成人| 亚洲网站视频福利| 久久国产精品久久久久久电车| 蜜臀a∨国产成人精品| 久久免费黄色| 亚洲精品一区二区在线| 亚洲福利av| 在线亚洲高清视频| 久久爱www.| 亚洲国产综合在线| 亚洲综合精品一区二区| 麻豆av一区二区三区| 欧美日韩一区二区三区在线| 国产日韩精品一区二区| 亚洲国产精品美女| 久久美女性网| 一区二区三区视频在线观看| 久久久亚洲成人| 国产欧美日韩亚洲一区二区三区 | 久久免费国产精品| 欧美日韩一区二区三区在线| 亚洲精品一区二区三区不| 久久精品一区蜜桃臀影院| 一区二区精品国产| 欧美日韩亚洲视频一区| 最新国产の精品合集bt伙计| 久久国产一区| 欧美一区二区三区在线播放| 国产精品a级| 香蕉久久夜色精品国产使用方法| 亚洲日本中文字幕免费在线不卡| 免费成人av资源网| 亚洲精品乱码久久久久久日本蜜臀 | 黄网动漫久久久| 亚洲欧美日韩中文在线制服| 亚洲乱码国产乱码精品精可以看 | 国产性天天综合网| 久久综合九色九九| 欧美日韩一区在线播放| 一区二区国产精品| 激情欧美丁香| 日韩视频二区| 国产精品免费看片| 免费在线看一区| 国产精品福利在线观看网址| 久久久精品日韩| 亚洲一区国产精品| 久久只有精品| 欧美一区二区三区在| 欧美激情视频给我| 久久久不卡网国产精品一区| 欧美日韩免费视频| 亚洲国产精品女人久久久| 国产一区二区观看| 亚洲视频欧美在线| 99精品国产热久久91蜜凸| 欧美影院视频| 欧美亚洲一区二区在线| 欧美视频在线一区| 亚洲免费av电影| 亚洲精品中文字幕在线观看| 性久久久久久久久| 久久久夜精品| 国产一区二区三区最好精华液| 亚洲性夜色噜噜噜7777| 一区二区电影免费观看| 美女精品视频一区| 亚洲人成网站777色婷婷| 欧美一区二区三区婷婷月色 | 亚洲国产精品传媒在线观看| 国产欧美日韩三区| 欧美在线视频免费| 久久久久久久久综合| 韩曰欧美视频免费观看| 欧美一区二区免费视频| 欧美福利电影网| 亚洲免费精彩视频| 国产精品丝袜久久久久久app| 亚洲中字在线| 蜜臀a∨国产成人精品| 99国产精品国产精品毛片| 欧美日韩三区四区| 午夜精品一区二区在线观看| 欧美不卡福利| 亚洲永久字幕| 亚洲黄色成人| 国产一区二区视频在线观看 | 欧美成人嫩草网站| 在线综合亚洲欧美在线视频| 国产日韩精品在线播放| 欧美精品一区三区| 久久精品一区二区三区四区 | 99国产精品国产精品毛片| 久久久久**毛片大全| 一本色道久久综合狠狠躁篇怎么玩 | 亚洲欧美日韩一区在线| 国产精品一香蕉国产线看观看 | 狠狠噜噜久久| 欧美性一二三区| 欧美日产国产成人免费图片| 模特精品裸拍一区| 美日韩精品视频免费看| 久久久久国产成人精品亚洲午夜| 亚洲欧美不卡| 欧美一级播放| 久久福利视频导航| 久久久夜夜夜| 久久先锋资源| 欧美日本亚洲| 国产精品大片| 国产一区视频网站| 韩国一区二区三区在线观看| 国产一区二区三区日韩| 亚洲精品一区二区三区樱花 | 久久久久99精品国产片| 欧美激情 亚洲a∨综合| 国产真实乱偷精品视频免| 亚洲免费在线播放| 亚洲一级电影| 久久久久久久高潮| 日韩一区二区免费高清| 久久国产精品电影| 欧美国产日产韩国视频| 欧美日韩国产不卡| 一区二区在线看| 夜夜嗨av一区二区三区| 欧美在线你懂的| 亚洲国产日韩欧美| 亚洲伊人久久综合| 免费日韩成人| 好看的日韩视频| 欧美一区二区三区喷汁尤物| 最近中文字幕日韩精品| 欧美一级一区| 国产欧美午夜| 久久综合国产精品| 久久亚洲一区二区三区四区| 亚洲国产日韩欧美综合久久| 亚洲免费在线| 国产三级精品在线不卡| 亚洲性图久久| 国产精品一页| 久久久国际精品| 久久久久久久久综合| 亚洲精品久久久蜜桃| 亚洲乱码国产乱码精品精天堂| 国产精品sm| 欧美一进一出视频| 性欧美暴力猛交另类hd| 一区二区在线视频播放| 欧美国产一区二区| 欧美日韩国产一中文字不卡| 亚洲欧美自拍偷拍| 欧美精品www在线观看| 久久福利精品| 久久婷婷av| 欧美精品在线观看| 亚洲欧美日本伦理| 国产精品久久久久久久电影| 91久久在线| 99亚洲视频| 国产精品一区视频网站| 国产精品白丝av嫩草影院| 女女同性精品视频| 国产区在线观看成人精品| 一二三区精品| 亚洲欧美日韩国产一区二区| 六月婷婷一区| 牛牛影视久久网| 亚洲成色777777在线观看影院| 日韩一级裸体免费视频| 精品成人一区| 午夜精品一区二区三区在线视 | 欧美日韩日韩| 日韩天堂在线观看| 亚洲欧美伊人| 国产一区二区在线观看免费| 欧美电影免费观看大全| 理论片一区二区在线| 国产一区av在线| 欧美成人午夜激情视频| 亚洲人成网在线播放| 先锋影音网一区二区| 国产日韩综合| 麻豆久久久9性大片| 欧美成人一区二区三区片免费| 国产日韩欧美精品综合| 午夜亚洲福利| 最近中文字幕mv在线一区二区三区四区 | 亚洲伦理在线观看| 欧美一区午夜精品| 在线观看三级视频欧美|