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

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>
            欧美一区二区三区视频免费播放| 亚洲一级免费视频| 久久久之久亚州精品露出| 国产中文一区二区三区| 午夜精品亚洲一区二区三区嫩草| 尤物99国产成人精品视频| 久久福利一区| 久久成人免费电影| 国内一区二区在线视频观看| 另类图片国产| 欧美成人高清| 亚洲午夜精品福利| 亚洲男人av电影| 韩国三级电影一区二区| 亚洲国产成人精品久久| 欧美久久精品午夜青青大伊人| 国产免费一区二区三区香蕉精| 久久国产精品亚洲77777| 久久国产精品毛片| 亚洲国产专区校园欧美| 一区二区高清视频| 国产日韩在线看| 欧美刺激性大交免费视频| 欧美日产一区二区三区在线观看 | 狼人天天伊人久久| 99精品黄色片免费大全| 午夜精品网站| 99精品久久久| 久久都是精品| 国产精品99久久99久久久二8| 欧美一级一区| 夜夜嗨av一区二区三区网页| 新67194成人永久网站| 亚洲激情一区二区三区| 亚洲欧洲av一区二区| 91久久国产自产拍夜夜嗨| 亚洲视频综合在线| 亚洲国产另类久久精品| 亚洲欧美精品在线观看| 亚洲精品一区久久久久久| 欧美一区二区在线| 亚洲五月六月| 欧美1区2区3区| 欧美在线在线| 欧美午夜精品久久久久久浪潮| 老牛嫩草一区二区三区日本| 欧美性大战久久久久久久蜜臀| 牛牛影视久久网| 国产一本一道久久香蕉| 久久午夜电影网| 久久久久久成人| 亚洲欧美一区在线| 欧美乱妇高清无乱码| 欧美激情精品久久久久久黑人 | 欧美日韩一区二区三区高清| 欧美电影免费观看大全| 激情欧美一区| 欧美在线中文字幕| 欧美亚洲综合久久| 久久久久免费| 久久久久久69| 国产日韩欧美在线看| 亚洲视频欧美视频| 中文欧美在线视频| 欧美日韩国产欧美日美国产精品| 亚洲福利视频二区| 亚洲激情av| 欧美成年网站| 亚洲欧洲日韩女同| 日韩亚洲欧美综合| 欧美日韩成人在线| 99精品欧美一区| 一区二区三区精品久久久| 欧美日本一区二区三区| 91久久精品国产91性色| 一区二区三区久久久| 欧美日本视频在线| 日韩一区二区精品| 午夜一区不卡| 黄色精品一区| 美女亚洲精品| 亚洲精品三级| 亚洲欧美视频一区二区三区| 国产精品午夜国产小视频| 香蕉久久夜色精品国产使用方法 | 国产一区二区日韩| 欧美中文字幕| 亚洲国产日韩欧美在线图片 | 欧美性久久久| 亚洲欧美激情视频在线观看一区二区三区| 亚洲欧美日韩视频二区| 国产九色精品成人porny| 欧美专区福利在线| 欧美freesex交免费视频| 亚洲精品一区中文| 国产精品久久久久一区二区三区共| 亚洲一区二区在线免费观看视频| 久久久久综合网| 亚洲日本在线观看| 国产精品嫩草久久久久| 久久久久久久网| 99精品欧美一区二区三区综合在线 | 香蕉久久夜色精品| 免费成人av在线| 亚洲视频一区在线| 黄网动漫久久久| 欧美日韩一区三区四区| 久久精品最新地址| 亚洲美女av电影| 久久久久久夜精品精品免费| 亚洲毛片在线免费观看| 国产丝袜美腿一区二区三区| 欧美激情在线免费观看| 欧美一区二区三区另类 | 欧美一区二区三区视频| 亚洲国产欧美日韩| 国产精品一区二区三区免费观看| 六月婷婷一区| 久久精品伊人| 亚洲视频中文字幕| 欧美激情欧美激情在线五月| 久久精精品视频| 一区二区三区四区五区精品视频 | 欧美成人在线影院| 欧美在线三级| 亚洲一级黄色片| 亚洲精品在线视频观看| 免费观看成人| 久久久久高清| 欧美在线短视频| 亚洲欧美日本国产有色| 日韩视频免费| 亚洲人成人77777线观看| 精品1区2区3区4区| 国产日韩欧美亚洲一区| 国产精品日韩一区二区三区| 欧美日韩一区在线观看| 欧美久久久久久蜜桃| 欧美高清在线| 一本一本a久久| 亚洲激情在线观看| 亚洲国产精品v| 欧美国产精品人人做人人爱| 米奇777在线欧美播放| 久久免费视频在线观看| 久久av资源网站| 久久av一区二区三区漫画| 午夜精品久久久久久久久久久久久| 一本色道久久88精品综合| 99热精品在线观看| 亚洲区在线播放| 99精品视频免费观看| 在线视频精品| 亚洲午夜成aⅴ人片| 亚洲一二三区视频在线观看| 亚洲欧美精品一区| 欧美一二区视频| 久久久另类综合| 欧美成人在线免费观看| 欧美黄色日本| 亚洲欧洲视频在线| 亚洲美女在线视频| 亚洲一区二区在线视频| 欧美一级久久久| 久久免费午夜影院| 欧美激情aaaa| 国产精品久久久久久久午夜 | 欧美日韩一区二区高清| 国产精品区一区二区三区| 国产精品中文字幕欧美| 很黄很黄激情成人| 亚洲黄色成人网| 亚洲一区二区三区午夜| 久久久综合精品| 亚洲人体影院| 亚洲欧美另类久久久精品2019| 久久久精品一区| 欧美揉bbbbb揉bbbbb| 狠狠久久亚洲欧美| 亚洲伦理在线| 欧美诱惑福利视频| 欧美国产综合视频| 亚洲一区二区高清| 久久一区中文字幕| 国产精品videosex极品| 一区二区三区在线观看视频 | 国产乱码精品一区二区三区忘忧草| 激情文学一区| 亚洲一区免费网站| 欧美a级一区| 亚洲欧美制服中文字幕| 欧美国产视频在线| 国产一区二三区| 亚洲小说欧美另类社区| 裸体丰满少妇做受久久99精品| 99在线热播精品免费| 美国十次了思思久久精品导航| 国产精品午夜av在线| 日韩亚洲精品在线| 久色成人在线|