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

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)

我參與的團隊

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

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


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   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>
            亚洲欧美国产一区二区三区| 国产精品私房写真福利视频 | 狠狠色丁香久久综合频道 | 亚洲先锋成人| 一本色道久久88精品综合| 久久精品国产欧美激情| 欧美亚洲在线观看| 欧美日韩精品免费观看| 欧美黄色一区二区| 在线免费观看成人网| 亚洲欧美成人一区二区在线电影| 一区二区三区高清在线| 欧美电影免费网站| 欧美激情一区三区| 亚洲欧洲另类| 免费成人性网站| 女主播福利一区| 又紧又大又爽精品一区二区| 欧美一区二区三区的| 久久激情视频| 国产一区香蕉久久| 欧美在线亚洲| 乱人伦精品视频在线观看| 国产日韩在线视频| 欧美一区二区大片| 久久影音先锋| 亚洲成人资源网| 牛牛影视久久网| 亚洲国内欧美| 99精品视频免费观看视频| 欧美激情视频在线播放| 亚洲区一区二| 亚洲一区二区在线视频| 国产精品视频99| 午夜精品三级视频福利| 久久久久99| 在线免费精品视频| 欧美大片第1页| 日韩视频免费观看高清完整版| 中文av字幕一区| 国产精品男gay被猛男狂揉视频| 午夜日韩在线| 免费成人黄色片| 亚洲精品激情| 国产精品盗摄一区二区三区| 香蕉免费一区二区三区在线观看| 开心色5月久久精品| 亚洲精品乱码久久久久久日本蜜臀 | 一区二区视频免费完整版观看| 久久精品夜色噜噜亚洲a∨| 欧美成人免费在线视频| 一本色道久久综合亚洲二区三区| 国产精品久久久一本精品| 亚洲欧美中文另类| 牛夜精品久久久久久久99黑人| 亚洲精品一区二区三区蜜桃久| 欧美日一区二区在线观看| 欧美在线网站| 日韩写真在线| 久久蜜桃香蕉精品一区二区三区| 亚洲人人精品| 国产美女一区二区| 欧美成人亚洲| 亚洲欧美日韩另类精品一区二区三区| 久久嫩草精品久久久精品一| 亚洲精品一区二区三区樱花| 国产精品伊人日日| 欧美福利网址| 久久成人精品电影| 日韩西西人体444www| 久久久久国产精品一区三寸| 亚洲美女毛片| 国产在线精品成人一区二区三区| 欧美激情综合色| 久久超碰97人人做人人爱| 99成人在线| 欧美激情亚洲一区| 久久乐国产精品| 亚洲一区二区在线免费观看| 亚洲黄页视频免费观看| 国产一区二区三区奇米久涩| 欧美色大人视频| 欧美激情精品久久久久久免费印度 | 国产精品久久久对白| 欧美成年人视频网站| 久久精品噜噜噜成人av农村| 亚洲午夜久久久| 亚洲乱码国产乱码精品精| 欧美ed2k| 久热精品视频在线| 久久精品一区蜜桃臀影院 | 一区二区三区产品免费精品久久75| 免费视频久久| 久久午夜电影网| 久久久久九九九| 久久久五月天| 久久不见久久见免费视频1| 亚洲一区二区精品视频| 一区二区三区**美女毛片 | 亚洲黑丝在线| 亚洲第一黄色| 亚洲国产精品成人综合| 尤物网精品视频| 精品av久久久久电影| 国语自产精品视频在线看| 国产综合网站| 激情小说亚洲一区| 亚洲福利精品| 亚洲国产欧美精品| 亚洲精品美女久久7777777| 亚洲三级影片| 一区二区三区免费在线观看| 亚洲午夜精品久久久久久浪潮 | 亚洲精品一区在线观看香蕉| 亚洲精品午夜| 亚洲视频在线观看视频| 亚洲婷婷综合色高清在线| 亚洲在线观看视频网站| 香蕉乱码成人久久天堂爱免费| 欧美在线播放视频| 久久精品91久久久久久再现| 久久偷看各类wc女厕嘘嘘偷窃| 久久久视频精品| 欧美福利在线| 国产精品久久久久久久免费软件 | 亚洲专区一区| 欧美亚洲一区二区三区| 久久久不卡网国产精品一区| 欧美 日韩 国产精品免费观看| 欧美激情视频一区二区三区免费 | 亚洲国产欧美一区| 亚洲少妇自拍| 久久成人综合网| 欧美成人自拍| 国产精品一区二区三区四区| 伊人色综合久久天天| 亚洲裸体在线观看| 欧美一区高清| 亚洲国产激情| 亚洲自拍高清| 美女国产精品| 国产精品久久久久9999吃药| 韩国美女久久| 一区二区欧美日韩视频| 久久久久综合一区二区三区| 亚洲福利小视频| 午夜亚洲视频| 欧美日韩三级| 一区二区三区在线免费视频| 在线视频欧美一区| 久久综合影视| 亚洲社区在线观看| 欧美 日韩 国产一区二区在线视频| 国产精品丝袜白浆摸在线| 亚洲人成免费| 久久久亚洲人| 在线视频精品一| 欧美不卡一卡二卡免费版| 国产精品一区久久| 在线一区免费观看| 欧美电影打屁股sp| 午夜精品理论片| 欧美日韩一区免费| 亚洲美女在线一区| 久久综合影视| 小黄鸭精品aⅴ导航网站入口| 欧美日韩久久不卡| 亚洲精品国产精品乱码不99| 久久人人爽爽爽人久久久| 亚洲午夜极品| 欧美日本精品在线| 亚洲欧洲日本专区| 欧美/亚洲一区| 久久久99精品免费观看不卡| 国产精品亚洲一区| 亚洲欧美日本在线| 99亚洲一区二区| 欧美日韩成人一区二区三区| 亚洲黄色在线观看| 欧美sm极限捆绑bd| 久久亚洲风情| 亚洲高清在线视频| 久久久久久有精品国产| 午夜在线精品| 国产日韩精品在线| 欧美一区成人| 西瓜成人精品人成网站| 国产美女精品在线| 久久aⅴ国产欧美74aaa| 亚洲综合国产| 国产日韩欧美在线播放| 久久精品男女| 欧美一区在线直播| 精品福利电影| 亚洲成色www8888| 欧美国产成人精品| 亚洲午夜av电影| 亚洲制服av| 国内揄拍国内精品久久| 欧美 日韩 国产 一区|