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

The Way of C++

  C++博客 :: 首頁 :: 聯(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ì)

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

    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!
  回復(fù)  更多評論
  

# 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. -_-  回復(fù)  更多評論
  

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

should be

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

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美日韩直播| 99精品久久久| 一区二区精品| 日韩一级精品| 亚洲免费观看高清完整版在线观看熊 | 99这里只有精品| 99国产精品视频免费观看一公开| 亚洲国产欧美一区二区三区久久 | 久久综合伊人77777麻豆| 欧美影院在线| 久久精品一区| 欧美激情国产日韩| 国产精品video| 国产精品中文字幕在线观看| 国内成人在线| 一区二区三区成人精品| 亚洲欧美国产高清| 久久人人97超碰人人澡爱香蕉| 欧美mv日韩mv国产网站| av成人国产| 久久久免费av| 欧美午夜影院| 亚洲国产欧美在线人成| 亚洲欧美成人综合| 欧美高清视频在线观看| 一本色道久久99精品综合 | 欧美一区二区三区在| 蜜桃伊人久久| 国产日韩亚洲欧美精品| 亚洲欧洲日韩综合二区| 欧美一级淫片播放口| 欧美韩日一区| 欧美一区二区三区免费观看视频| 欧美精品一区二区三区久久久竹菊 | 亚洲欧美视频一区| 欧美国产一区视频在线观看 | 亚洲欧美日韩爽爽影院| 亚洲国产经典视频| 亚洲在线中文字幕| 欧美国产精品一区| 国内精品免费在线观看| 亚洲午夜日本在线观看| 欧美激情一区二区三区在线视频观看 | 欧美影院在线| 亚洲深夜影院| 欧美激情亚洲另类| 伊人久久大香线蕉综合热线| 午夜精品久久久久久久99热浪潮 | 久久se精品一区精品二区| 国产精品草草| 在线综合亚洲欧美在线视频| 亚洲欧美卡通另类91av| 久久精品毛片| 国产精品入口尤物| 国产精品99久久久久久宅男 | 欧美一区二区三区视频在线| 欧美视频福利| 一区二区久久| 亚洲国产精品国自产拍av秋霞| 欧美在线观看www| 国产欧美一区二区三区国产幕精品| 一本色道久久加勒比88综合| 亚洲国产视频直播| 久久综合激情| 亚洲激情av| 亚洲激情自拍| 欧美三区视频| 亚洲尤物视频在线| 国产精品99久久久久久白浆小说 | 欧美一区二区免费视频| 亚洲免费成人| 国产精品狼人久久影院观看方式| 亚洲伊人一本大道中文字幕| 日韩一级二级三级| 国产精品国码视频| 欧美在线电影| 久久久久久欧美| 黄色小说综合网站| 欧美激情国产高清| 欧美日本一区二区高清播放视频| 国产精品99久久久久久久女警 | 久久精品一区| 久久影视三级福利片| 亚洲黄色成人网| 一区二区久久久久| 国产乱理伦片在线观看夜一区| 久久精品网址| 免费在线欧美黄色| 亚洲伊人久久综合| 久久国产精品久久精品国产| 亚洲福利视频二区| 日韩一级大片在线| 国产欧美在线观看一区| 欧美sm视频| 国产精品99免视看9| 久久久久中文| 欧美日韩美女在线观看| 午夜在线电影亚洲一区| 久久夜色精品国产欧美乱| 一本久久a久久精品亚洲| 亚洲一区精彩视频| 亚洲国产高潮在线观看| 99re热这里只有精品视频| 乱人伦精品视频在线观看| 中文在线资源观看网站视频免费不卡| 国产精品一级久久久| 欧美激情一区二区三区全黄| 国产欧美三级| 亚洲精品久久视频| 国产午夜精品全部视频播放 | 欧美大香线蕉线伊人久久国产精品| 日韩亚洲一区在线播放| 欧美一区二区三区视频| 一区二区三区久久网| 久久精品视频播放| 亚洲免费在线精品一区| 免费成人高清| 开心色5月久久精品| 国产精品久久久久久久久久直播 | 亚洲片国产一区一级在线观看| 国产精品99久久久久久有的能看| 亚洲第一中文字幕在线观看| 亚洲欧美日韩一区二区| 中文一区二区| 欧美黄色aaaa| 亚洲国产精品久久久久久女王| 国产一区二区日韩精品欧美精品| 一本色道久久综合亚洲精品婷婷| 亚洲精品国精品久久99热| 久久天堂av综合合色| 久久午夜色播影院免费高清| 国产欧美在线观看一区| 亚洲欧美一区二区三区在线 | 亚洲黄色成人| 另类亚洲自拍| 欧美顶级艳妇交换群宴| 黄色精品一区二区| 久久久久一区二区三区| 久久久久天天天天| 激情久久综合| 久久最新视频| 亚洲国产精品成人| 亚洲巨乳在线| 欧美视频四区| 亚洲女人小视频在线观看| 欧美尤物一区| 亚洲大片一区二区三区| 欧美国产第一页| 一本久久a久久精品亚洲| 亚洲综合精品| 国产一区二区三区视频在线观看| 久久久99久久精品女同性| 欧美大色视频| 亚洲视频axxx| 国模私拍视频一区| 久久综合99re88久久爱| 亚洲第一视频网站| 亚洲色图制服丝袜| 国内精品久久久久久影视8| 欧美1区2区| 亚洲无玛一区| 欧美a级大片| 亚洲色诱最新| 亚洲国产婷婷香蕉久久久久久99| 日韩亚洲欧美高清| 欧美99在线视频观看| 亚洲精品久久久蜜桃| 午夜国产精品视频| 国产有码在线一区二区视频| 欧美成人免费在线| 亚洲性线免费观看视频成熟| 欧美在线free| 日韩午夜av在线| 国产日韩欧美精品| 欧美日产一区二区三区在线观看| 亚洲欧美激情精品一区二区| 欧美激情第8页| 久久精品人人| 中文亚洲视频在线| 在线观看欧美视频| 国产精品嫩草99av在线| 欧美不卡一卡二卡免费版| 亚洲女性喷水在线观看一区| 亚洲国产成人精品女人久久久 | 国产精品捆绑调教| 欧美成人精品三级在线观看| 亚洲综合国产| 亚洲免费观看| 欧美激情视频免费观看| 翔田千里一区二区| 一区二区三区鲁丝不卡| 永久久久久久| 国产一本一道久久香蕉| 欧美视频三区在线播放| 毛片av中文字幕一区二区| 亚洲欧美一区二区三区久久| 一区二区三区**美女毛片| 亚洲国产精品电影在线观看| 麻豆成人91精品二区三区| 久久精品一区四区|