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

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>
            免费在线亚洲| 久久激情中文| 亚洲精品免费在线观看| 欧美va亚洲va香蕉在线| 亚洲伦理久久| 亚洲午夜91| 极品日韩久久| 91久久久久久久久| 欧美午夜片欧美片在线观看| 久久精品免费| 欧美大片18| 午夜精品久久久久久久久| 久久激情视频免费观看| 亚洲精品一区中文| 亚洲综合精品自拍| 亚洲国产另类精品专区 | 国产亚洲精品高潮| 蜜桃久久av一区| 欧美日韩亚洲一区二区三区在线观看 | 国产精品久久网站| 免播放器亚洲| 欧美视频一区在线观看| 久久精品国产精品亚洲综合| 欧美成人精品高清在线播放| 欧美一区二区成人| 欧美jizz19性欧美| 久久精品电影| 欧美日韩在线精品一区二区三区| 亚洲欧美在线高清| 欧美高清不卡| 老司机午夜精品| 欧美天天综合网| 欧美激情一区| 国内视频精品| 亚洲网站在线| 99热在这里有精品免费| 欧美淫片网站| 先锋影音国产一区| 欧美日本在线| 欧美激情a∨在线视频播放| 国产精品夜夜夜一区二区三区尤| 亚洲承认在线| 伊人久久大香线| 欧美一级网站| 午夜精品久久久久久久99热浪潮| 欧美日本免费一区二区三区| 女女同性女同一区二区三区91| 国产欧美va欧美va香蕉在| 亚洲精品久久久久中文字幕欢迎你| 狠狠色丁香婷婷综合久久片| 亚洲男人影院| 欧美一级片久久久久久久| 欧美日韩中文字幕| 日韩亚洲欧美在线观看| 一本色道久久88亚洲综合88| 猛干欧美女孩| 欧美国产日韩xxxxx| 一色屋精品视频在线看| 久久激情一区| 美女精品在线观看| 在线观看欧美| 久久影院午夜片一区| 米奇777在线欧美播放| 欲香欲色天天天综合和网| 欧美一区二区三区四区在线| 久久精品国产亚洲5555| 国产夜色精品一区二区av| 欧美亚洲网站| 免费在线观看日韩欧美| 最新成人在线| 欧美精品18| 在线视频欧美一区| 欧美伊久线香蕉线新在线| 国产日韩在线视频| 久久嫩草精品久久久精品| 你懂的视频欧美| 亚洲蜜桃精久久久久久久| 欧美日韩综合网| 亚洲一区二区影院| 久久嫩草精品久久久精品| 在线成人欧美| 欧美精品综合| 亚洲欧美怡红院| 美日韩丰满少妇在线观看| 亚洲精品一区二区三| 欧美午夜精品久久久| 亚洲欧洲av一区二区| 欧美电影在线| 亚洲专区一二三| 狠狠入ady亚洲精品经典电影| 美日韩免费视频| 国产精品99久久不卡二区| 久久久久久噜噜噜久久久精品| 在线观看视频免费一区二区三区| 欧美精品一区在线播放| 亚洲欧美综合另类中字| 欧美成人精品在线视频| 亚洲综合二区| 亚洲国产婷婷| 国产精品永久免费| 欧美国产日韩免费| 午夜影视日本亚洲欧洲精品| 亚洲高清三级视频| 欧美亚洲在线观看| 日韩一区二区高清| 国产视频久久久久| 欧美日韩精品| 久久夜色精品国产欧美乱| 亚洲深夜影院| 亚洲黄色影院| 老司机午夜精品| 性伦欧美刺激片在线观看| 亚洲欧洲一区二区三区在线观看| 国产精品人人爽人人做我的可爱 | 久久视频一区| 亚洲欧美综合精品久久成人| 亚洲乱码国产乱码精品精| 六月婷婷久久| 欧美在线视频观看免费网站| 一本到12不卡视频在线dvd| 激情欧美一区| 国产女人18毛片水18精品| 欧美日本一区二区视频在线观看| 久久aⅴ国产欧美74aaa| 亚洲一区欧美激情| 一本色道久久加勒比88综合| 欧美77777| 久久av红桃一区二区小说| 亚洲一区久久| 正在播放欧美视频| 91久久久在线| 亚洲第一二三四五区| 黄色av一区| 国产精品专区第二| 国产精品一区二区你懂的| 国产精品美腿一区在线看| 欧美亚男人的天堂| 欧美日韩一区精品| 欧美日韩免费观看一区三区| 欧美成人免费网站| 欧美成人网在线| 免费在线欧美黄色| 久久这里有精品视频| 老司机午夜免费精品视频| 久久久久久一区| 久久久久久精| 美女精品在线观看| 蜜桃久久精品一区二区| 免费一区视频| 欧美精品自拍偷拍动漫精品| 欧美激情一区在线| 欧美日韩伊人| 国产精品久久久久99| 国产精品视频一| 国产自产精品| 亚洲国内自拍| 亚洲一区二区三区四区五区黄| 亚洲一品av免费观看| 欧美一乱一性一交一视频| 久久久激情视频| 欧美激情91| 在线综合亚洲| 久久久久久久久久久久久9999| 蜜乳av另类精品一区二区| 欧美另类在线播放| 国产日韩欧美在线一区| 亚洲二区免费| 亚洲男女毛片无遮挡| 久久亚洲色图| 亚洲免费观看高清在线观看| 亚洲欧美日韩国产| 美女视频网站黄色亚洲| 国产精品扒开腿做爽爽爽视频 | 伊人色综合久久天天| 亚洲另类在线视频| 久久精品夜色噜噜亚洲aⅴ| 欧美黄色aa电影| 午夜精品一区二区三区在线视| 久久精品一区蜜桃臀影院 | 欧美一区二区精品久久911| 欧美国产日韩二区| 国产一区二区三区日韩欧美| 亚洲精品欧洲| 久久三级福利| 亚洲在线国产日韩欧美| 欧美超级免费视 在线| 国产伦精品免费视频| 亚洲精品少妇30p| 久久青草久久| 亚洲制服av| 欧美日本国产| 亚洲国产精品国自产拍av秋霞| 午夜精品电影| 日韩一级免费| 欧美bbbxxxxx| 亚洲精品黄色| 欧美插天视频在线播放| 国产自产高清不卡| 久久成人综合网| 亚洲一区二区三区四区在线观看|