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

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>
            欧美高清成人| 亚洲国产日韩一区二区| 宅男精品视频| 欧美国产日本韩| 久久视频国产精品免费视频在线| 两个人的视频www国产精品| 国产一区二区激情| 欧美电影免费观看| 欧美日韩国产小视频在线观看| 国产欧美日韩亚洲| 久久婷婷一区| 欧美黄免费看| 午夜在线精品偷拍| 亚洲人人精品| 国产精品劲爆视频| 久久一区二区三区四区五区| 欧美超级免费视 在线| 亚洲一本视频| 久久久久久综合| 99精品欧美一区二区三区综合在线| 欧美一级大片在线观看| 久久人人超碰| 亚洲制服丝袜在线| 老司机免费视频一区二区| 国产一区二区三区的电影| 亚洲国产精品久久久久久女王| 久久er99精品| 99亚洲精品| 久久精品国产99国产精品澳门| 国产精品视频一二三| 一本久道久久综合婷婷鲸鱼| 免费欧美在线| 欧美一区日韩一区| 国产精品国产精品| 欧美肥婆在线| 欧美 日韩 国产在线| 欧美一区二区三区免费看| 欧美激情免费观看| 久久野战av| 国产欧美日韩精品丝袜高跟鞋| 亚洲在线视频观看| 欧美黄污视频| 蜜臀91精品一区二区三区| 国产乱肥老妇国产一区二| 亚洲精品国产视频| 亚洲国产电影| 久久免费精品视频| 久久青草福利网站| 国产一区二区三区高清播放| 久久午夜精品一区二区| 国产精品一区二区你懂的| 亚洲六月丁香色婷婷综合久久| 亚洲在线中文字幕| 亚洲国产日韩欧美综合久久 | 狠狠色丁香婷婷综合影院| 午夜在线一区二区| 欧美啪啪成人vr| 亚洲国产精品一区二区尤物区| 欧美精品一区二区三区四区| 蜜桃久久精品一区二区| 一区二区亚洲| 久久久久网站| 噜噜噜躁狠狠躁狠狠精品视频| 欧美jizz19性欧美| 欧美成人嫩草网站| 亚洲第一黄网| 欧美成人免费在线视频| 欧美电影美腿模特1979在线看| 欧美日韩国产精品成人| 亚洲人成在线观看网站高清| 日韩一级大片| 欧美视频在线免费| 亚洲一区免费视频| 久久精彩免费视频| 激情成人综合| 欧美成人一区二区三区在线观看 | 欧美日韩在线直播| 99视频一区二区三区| 亚洲在线观看视频| 国产欧美一区二区精品性色| 久久se精品一区精品二区| 男人天堂欧美日韩| 日韩图片一区| 国产精品一区视频| 亚洲福利视频二区| 一区二区三区不卡视频在线观看| 亚洲综合好骚| 久久夜色精品亚洲噜噜国产mv| 欧美日韩理论| 亚洲欧美日韩爽爽影院| 美女在线一区二区| 在线亚洲高清视频| 国产欧美在线播放| 欧美激情国产精品| 欧美一区二区视频在线| 欧美国产三区| 午夜亚洲视频| 亚洲人成网站精品片在线观看| 午夜精品久久久久99热蜜桃导演| 日韩一级二级三级| 国产精品夜夜嗨| 免费在线亚洲| 亚洲综合色在线| 亚洲激情国产| 久久一区免费| 亚洲欧美成人综合| 亚洲国产午夜| 国产午夜亚洲精品理论片色戒| 一区二区久久久久久| 麻豆精品传媒视频| 亚洲欧美日韩精品久久亚洲区| 欧美日本在线| 久久黄色网页| 亚洲一区久久久| 亚洲欧洲综合另类在线| 老司机免费视频久久| 激情欧美丁香| 国产精品国产三级国产普通话三级| 亚洲精品影院在线观看| 最新日韩av| 国产一区在线观看视频| 欧美网站在线观看| 欧美另类亚洲| 欧美aa在线视频| 久久久夜精品| 欧美一区=区| 欧美r片在线| 久久福利电影| 欧美在线首页| 午夜精品久久久久久久白皮肤| 国产裸体写真av一区二区| 欧美日韩精品免费观看视频完整| 亚洲精品国产系列| 亚洲免费成人av| 欧美在线观看日本一区| 亚洲国产清纯| 亚洲精品在线视频| 免费欧美电影| 久久九九精品| 久久久久久久久久久久久女国产乱 | 久久午夜视频| 亚洲国产精品www| 欧美xx69| 欧美大片一区| 亚洲国产精品日韩| 亚洲欧美日韩精品久久| 亚洲无线一线二线三线区别av| 国产精品一级久久久| 国产精品久久久久77777| 国产精品久久久久影院色老大 | 亚洲精品乱码久久久久| 亚洲自拍偷拍福利| 亚洲欧美电影在线观看| 欧美在线播放一区二区| 久久久99精品免费观看不卡| 91久久亚洲| 国产精品国产三级国产aⅴ入口| 欧美一二三视频| 欧美一级在线视频| 日韩视频免费观看| 一本色道久久88综合日韩精品| 久久乐国产精品| 欧美暴力喷水在线| 亚洲理论在线| 欧美一区二区三区视频在线 | 亚洲视频第一页| 午夜国产精品影院在线观看| 久久精品国产2020观看福利| 久久午夜精品一区二区| 亚洲国产裸拍裸体视频在线观看乱了中文 | 久久久精彩视频| 欧美多人爱爱视频网站| 欧美日韩中文字幕在线| 国产亚洲欧美另类中文| 亚洲精品美女在线观看| 亚洲欧美日韩视频二区| 亚洲成人自拍视频| 国产目拍亚洲精品99久久精品 | 亚洲精品黄网在线观看| 在线午夜精品自拍| 久久久久久电影| 亚洲欧美在线免费观看| 久久综合国产精品| 久久久激情视频| 欧美日韩视频在线一区二区| 国产午夜精品一区理论片飘花 | 欧美在线日韩精品| 欧美成人在线免费观看| 久久久久一区二区三区四区| 欧美日韩亚洲一区三区| 国内精品久久久久久影视8| 日韩小视频在线观看专区| 在线成人中文字幕| 亚洲一区美女视频在线观看免费| 99日韩精品| 久久久精品国产一区二区三区| 欧美一级久久| 亚洲精品日韩综合观看成人91| 亚洲国产精品女人久久久| 欧美高清视频|