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

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 閱讀(1084) 評論(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>
            久久麻豆一区二区| 免费高清在线一区| 99v久久综合狠狠综合久久| 麻豆成人精品| 亚洲精品国产精品国自产观看| 久久国产夜色精品鲁鲁99| 欧美午夜在线一二页| 亚洲综合色婷婷| 亚洲一区二区三区在线看| 国产女人水真多18毛片18精品视频| 国产精品成人一区二区三区吃奶 | 久久riav二区三区| 亚洲永久免费av| 国内成人在线| 免费观看久久久4p| 欧美激情综合网| 亚洲欧美日韩成人高清在线一区| 麻豆国产精品777777在线| 免费欧美日韩国产三级电影| 一区二区av在线| 亚洲欧美日韩成人高清在线一区| 久久婷婷人人澡人人喊人人爽| 欧美日韩亚洲一区二区| 性色av一区二区怡红| 久久久久久穴| 日韩视频免费观看高清在线视频| 久久亚洲影院| 欧美日韩亚洲高清一区二区| 久久精品国产精品亚洲| 久久久久久国产精品mv| 日韩写真视频在线观看| 午夜精品福利视频| 99精品视频免费观看| 欧美在线视频一区| 在线亚洲精品福利网址导航| 欧美一二三区精品| 一级日韩一区在线观看| 久久精品99国产精品| 亚洲天堂第二页| 美日韩精品免费观看视频| 亚洲欧美日本国产专区一区| 欧美国产精品一区| 久久影视三级福利片| 国产精品久久久久久久浪潮网站 | 亚洲专区一区| 久热精品视频在线免费观看| 午夜在线电影亚洲一区| 欧美激情国产日韩| 麻豆国产精品va在线观看不卡 | 亚洲高清在线播放| 欧美午夜精品久久久久免费视| 亚洲精选91| 久久五月天婷婷| 久久riav二区三区| 国产精品一区二区你懂得| 亚洲精品无人区| 亚洲乱码精品一二三四区日韩在线| 欧美激情一区二区| 黄色小说综合网站| 欧美一区二区三区精品| 亚洲午夜精品网| 欧美日韩久久| 亚洲理论在线| 一区二区三区日韩欧美| 欧美伦理91| 亚洲人成在线观看| 中国女人久久久| 欧美日韩和欧美的一区二区| 亚洲日韩成人| 99精品视频免费| 欧美日韩久久| 一区二区三区日韩欧美精品| 99国产精品99久久久久久粉嫩| 亚洲天堂激情| 欧美亚洲自偷自偷| 国产伦精品一区二区三区在线观看| 快播亚洲色图| 亚洲第一黄色网| 欧美国产丝袜视频| 日韩一级网站| 欧美在线国产精品| 黄色小说综合网站| 蜜桃av噜噜一区| 亚洲三级网站| 香蕉成人啪国产精品视频综合网| 久久久久久久久久久久久女国产乱 | 亚洲欧美日韩在线| 久久国产日本精品| 1769国产精品| 欧美久久在线| 亚洲欧美日韩在线不卡| 猫咪成人在线观看| 一本久久综合亚洲鲁鲁| 国产精品www色诱视频| 久久成年人视频| 亚洲激情视频网站| 性久久久久久久| 亚洲国产精品尤物yw在线观看| 中日韩美女免费视频网站在线观看| 国精品一区二区| 欧美激情四色| 亚洲欧美日韩综合一区| 欧美 亚欧 日韩视频在线| 99综合视频| 黄色在线一区| 欧美日韩国产bt| 久久激情视频免费观看| 99视频一区二区| 米奇777在线欧美播放| 亚洲午夜在线观看视频在线| 精品69视频一区二区三区| 欧美精品一区二区高清在线观看| 欧美电影免费观看高清完整版| 国产亚洲精品久久久久久| 欧美jizz19性欧美| 午夜在线观看免费一区| 亚洲精品免费网站| 美女被久久久| 久久精品成人欧美大片古装| 一本色道88久久加勒比精品| 在线观看视频一区| 国产精品影音先锋| 欧美三区不卡| 欧美成人午夜剧场免费观看| 久久精品论坛| 亚洲一区二区影院| av成人天堂| 亚洲麻豆av| 亚洲国内在线| 亚洲第一页在线| 麻豆国产va免费精品高清在线| 1000精品久久久久久久久| 国产精品揄拍500视频| 欧美午夜激情视频| 欧美激情在线播放| 欧美成人黄色小视频| 久久综合久久88| 久久久久国产一区二区三区| 小嫩嫩精品导航| 午夜精品影院| 午夜欧美精品| 香蕉国产精品偷在线观看不卡| 免费成人黄色片| 麻豆亚洲精品| 欧美成人精品1314www| 蜜臀a∨国产成人精品 | 欧美精品一区二区久久婷婷| 米奇777在线欧美播放| 久久久精品tv| 久久人人爽爽爽人久久久| 欧美在线视频日韩| 久久久久欧美| 麻豆精品一区二区综合av| 美女网站久久| 欧美日韩成人在线观看| 欧美日韩一级视频| 国产精品视频精品视频| 国产欧美日韩亚洲精品| 国产偷自视频区视频一区二区| 欧美成人r级一区二区三区| 欧美国产免费| 欧美午夜宅男影院在线观看| 国产精品日本精品| 极品av少妇一区二区| 亚洲福利视频网站| 亚洲天堂男人| 久久精品成人一区二区三区 | 国产精品久久久久久久久搜平片 | 欧美色大人视频| 国产精品免费看片| 好吊成人免视频| 亚洲精品一区久久久久久| 亚洲网站视频| 久久男人av资源网站| 亚洲国产另类久久精品| 在线一区视频| 久久久噜噜噜久噜久久| 欧美大片免费观看| 欧美亚洲成人网| 精品91在线| 亚洲欧美国内爽妇网| 乱中年女人伦av一区二区| 亚洲精品系列| 久久精品国亚洲| 欧美理论片在线观看| 国产一区亚洲| 亚洲一区二区三区欧美| 老司机精品福利视频| 中文国产亚洲喷潮| 玖玖玖国产精品| 国产精品视屏| 夜夜爽www精品| 久久人人九九| 亚洲在线视频观看| 欧美精品在线观看| 伊人色综合久久天天| 欧美伊人久久大香线蕉综合69| 午夜精品视频在线观看| 亚洲国产高清一区| 午夜亚洲精品|