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

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 閱讀(1087) 評論(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..........  回復  更多評論
  


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一区二区三区不卡视频在线观看| 亚洲午夜在线| 欧美激情第一页xxx| 久久亚裔精品欧美| 亚洲欧洲日夜超级视频| 欧美大片网址| 欧美日韩国产综合视频在线| 亚洲免费小视频| 欧美一区二区三区另类| 伊人久久综合97精品| 亚洲国产精品福利| 欧美日本高清视频| 性8sex亚洲区入口| 葵司免费一区二区三区四区五区| 一二三区精品福利视频| 亚洲一区不卡| 原创国产精品91| 日韩亚洲欧美中文三级| 国产精品视频网站| 欧美成人国产一区二区| 国产精品久久久对白| 久久夜色撩人精品| 欧美日韩免费观看一区三区| 欧美一级成年大片在线观看| 免费日韩视频| 欧美中文字幕视频在线观看| 久久久综合网| 亚洲免费中文| 欧美aⅴ一区二区三区视频| 亚洲欧美精品中文字幕在线| 久久三级视频| 午夜久久久久久| 猛干欧美女孩| 久久久精品一区| 欧美午夜不卡视频| 欧美激情日韩| 合欧美一区二区三区| 亚洲一区二区伦理| 日韩午夜电影在线观看| 久久乐国产精品| 欧美一区视频在线| 欧美三日本三级少妇三2023| 欧美黑人多人双交| 伊甸园精品99久久久久久| 在线综合亚洲欧美在线视频| 亚洲精品免费在线观看| 久久久久久久久久码影片| 欧美中文在线观看国产| 欧美亚州一区二区三区| 亚洲精品激情| 亚洲免费观看高清完整版在线观看| 性欧美长视频| 亚洲欧美日韩综合aⅴ视频| 欧美日韩精品一区二区| 91久久精品国产91性色tv| 亚洲第一精品电影| 久久精品五月| 久久一本综合频道| 国产亚洲欧美日韩精品| 欧美亚洲自偷自偷| 欧美在线一二三| 国产日韩精品在线播放| 亚洲欧美日本伦理| 久久成人免费网| 国产一区二区视频在线观看| 亚洲欧美日韩一区| 久久看片网站| 黄色一区二区三区四区| 欧美在线播放一区| 女人色偷偷aa久久天堂| 亚洲黄一区二区| 欧美精品久久99| 99国产精品国产精品久久| 亚洲午夜精品网| 国产精品日韩欧美一区二区| 香蕉成人啪国产精品视频综合网| 欧美尤物巨大精品爽| 国产一区二区三区高清| 久久九九全国免费精品观看| 另类激情亚洲| 亚洲日本无吗高清不卡| 欧美日韩一区二区在线观看| 亚洲一级片在线看| 久久久久五月天| 亚洲欧洲一区二区三区久久| 欧美日韩国产电影| 一区二区三区高清不卡| 久久久免费精品视频| 亚洲激情专区| 国产精品久久久久永久免费观看| 午夜久久电影网| 欧美国产精品久久| 亚洲欧洲av一区二区| 红桃视频国产精品| 欧美久久久久久久久久| 欧美一级在线亚洲天堂| 亚洲国产一区二区三区高清| 亚洲专区在线| 亚洲第一区色| 欧美日韩一二区| 久久久久久穴| 中文有码久久| 亚洲成人在线视频网站| 午夜精品一区二区三区电影天堂| 影音先锋一区| 国产精品性做久久久久久| 快射av在线播放一区| 亚洲一区二区成人| 亚洲国产精品福利| 久久九九免费视频| 亚洲视频精品| 亚洲人成艺术| 经典三级久久| 国产女主播一区| 欧美另类在线观看| 久久这里有精品15一区二区三区| 国产精品99久久久久久久vr | 亚洲国产一二三| 国产精品一区久久久| 欧美理论视频| 麻豆精品在线观看| 久久大逼视频| 亚洲与欧洲av电影| 在线亚洲一区观看| 亚洲国产日韩精品| 欧美电影免费观看| 久久噜噜噜精品国产亚洲综合| 亚洲砖区区免费| 亚洲午夜精品久久| 一本色道久久综合亚洲精品婷婷| 亚洲黄色大片| 1024欧美极品| 伊人久久久大香线蕉综合直播| 国产一区二区高清视频| 国产精品一区视频网站| 国产精品免费视频观看| 国产精品高潮粉嫩av| 欧美视频国产精品| 欧美日韩一区二区视频在线| 欧美精品www在线观看| 欧美va天堂| 欧美精品99| 欧美日韩亚洲国产一区| 欧美日韩免费看| 欧美三级电影大全| 欧美网站在线| 国产精品一区二区三区观看| 国产精品午夜国产小视频| 国产精品一区二区久久久久| 国产欧美一区二区精品忘忧草| 国产精品午夜在线观看| 国产亚洲美州欧州综合国| 国产自产高清不卡| 在线日韩av片| 亚洲精品永久免费| 9l视频自拍蝌蚪9l视频成人| 亚洲一区影院| 久久久久久久久久码影片| 蜜月aⅴ免费一区二区三区| 欧美激情久久久久久| 亚洲精品偷拍| 亚洲欧美www| 久久精品一区二区国产| 欧美jizzhd精品欧美巨大免费| 欧美美女bb生活片| 国产伦精品一区二区三区高清版| 国产一区二区三区久久| 亚洲人成网站色ww在线| 亚洲尤物精选| 乱中年女人伦av一区二区| 亚洲人成人99网站| 亚洲在线视频| 免费成人av在线| 国产精品久久久久久久久免费 | 亚洲精品乱码久久久久久蜜桃麻豆 | 亚洲女同性videos| 久久久999| 欧美日韩综合视频| 国产一在线精品一区在线观看| 亚洲精品女人| 欧美综合二区| 亚洲精品久久久久久一区二区| 亚洲欧美日本国产专区一区| 久久中文欧美| 国产精品一区在线观看你懂的| 亚洲国产免费| 久久精品av麻豆的观看方式| 91久久精品国产91久久性色| 小黄鸭精品密入口导航| 欧美精品成人在线| 樱桃国产成人精品视频| 香蕉成人啪国产精品视频综合网| 免费高清在线一区| 午夜精品剧场| 国产精品v欧美精品v日韩| 亚洲福利视频在线| 久久久久久香蕉网| 亚洲午夜在线观看视频在线| 欧美激情网友自拍| 亚洲高清自拍|