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

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>
            亚洲少妇在线| 亚洲一区二区在线| 麻豆av一区二区三区久久| 激情久久久久久久| 久久综合给合| 麻豆久久精品| 99精品国产一区二区青青牛奶| 亚洲成在人线av| 欧美在线一区二区| 影音欧美亚洲| 最新热久久免费视频| 欧美日韩一区二区三区免费| 一区二区三区欧美日韩| 亚洲一二三区精品| 国产综合一区二区| 亚洲国产清纯| 国产精品任我爽爆在线播放| 久久精品中文字幕一区| 老妇喷水一区二区三区| 中日韩高清电影网| 久久国产88| 一本到高清视频免费精品| 亚洲欧美卡通另类91av | 欧美激情第二页| 欧美激情综合色综合啪啪| 午夜精品短视频| 久久夜色精品国产欧美乱极品| 亚洲精品小视频| 午夜一区不卡| 99精品久久久| 久久国产一区| 亚洲一区中文| 欧美1级日本1级| 欧美一区二区三区电影在线观看| 久久婷婷一区| 欧美资源在线观看| 欧美人妖另类| 欧美黄色日本| 国产综合在线看| 亚洲一区在线免费观看| 亚洲精品久久久久久久久久久| 亚洲欧美国产视频| 一区二区av在线| 久久综合久久综合久久综合| 翔田千里一区二区| 欧美日韩久久精品| 欧美成人精品激情在线观看| 国产精品日韩一区二区| 亚洲精品一区二| 亚洲黄一区二区| 久久精品中文字幕一区| 欧美中文字幕视频在线观看| 欧美国产高清| 欧美国产免费| 激情综合色丁香一区二区| 亚洲免费人成在线视频观看| 一区二区三区视频观看| 欧美成人免费网站| 欧美国产第一页| 亚洲国产小视频在线观看| 久久99伊人| 久久不射中文字幕| 国产美女扒开尿口久久久| 宅男噜噜噜66一区二区66| 一区二区91| 欧美亚男人的天堂| a4yy欧美一区二区三区| 在线一区观看| 国产精品成人v| 亚洲一级片在线看| 欧美亚洲一区在线| 国产手机视频精品| 久久精品欧美日韩| 久久婷婷国产综合国色天香| 含羞草久久爱69一区| 久久精品中文字幕免费mv| 欧美jizzhd精品欧美巨大免费| 一区二区三区在线免费播放| 久久青青草原一区二区| 欧美www视频| 亚洲免费高清| 国产精品久久久久久久7电影| 亚洲午夜电影| 久久九九热re6这里有精品| 一区二区视频在线观看| 免费永久网站黄欧美| 亚洲精品无人区| 性久久久久久久久久久久| 国产亚洲成人一区| 裸体丰满少妇做受久久99精品| 亚洲欧洲另类| 欧美一区二区三区在线观看| 狠狠色狠狠色综合日日五| 麻豆av一区二区三区| 夜夜嗨av一区二区三区中文字幕 | 久久男人av资源网站| 悠悠资源网久久精品| 欧美日韩国产综合一区二区| 亚洲一区二区动漫| 美女视频网站黄色亚洲| 中文亚洲视频在线| 韩日欧美一区二区三区| 欧美激情一区二区三级高清视频| 一区二区三区蜜桃网| 久久这里只有| 亚洲一区中文| 亚洲国产婷婷香蕉久久久久久99 | 欧美视频在线一区| 久久激情一区| 一区二区三区视频观看| 美国成人毛片| 亚洲欧美日韩高清| 亚洲国内精品在线| 国产精品视屏| 欧美激情一区二区三区全黄| 先锋影音久久久| 亚洲日本一区二区| 久久免费精品日本久久中文字幕| 亚洲作爱视频| 亚洲高清视频的网址| 国产女主播一区二区三区| 欧美国产另类| 久久久视频精品| 亚洲欧美春色| 一本色道久久88精品综合| 欧美成人免费在线| 久久黄色级2电影| 亚洲综合欧美日韩| 日韩亚洲视频在线| 亚洲国产精品t66y| 黄色国产精品| 国产婷婷精品| 国产精品一区二区黑丝| 欧美午夜电影在线| 欧美88av| 欧美高清成人| 欧美成人精品1314www| 久久久99爱| 欧美在线观看一区二区| 午夜精品久久久久久久久久久久| 99re66热这里只有精品3直播| 欧美激情一区三区| 欧美电影免费观看大全| 免费亚洲电影在线| 另类激情亚洲| 嫩草伊人久久精品少妇av杨幂| 久久久精品欧美丰满| 久久久久国产精品厨房| 久久精品一区二区三区中文字幕| 欧美影院成人| 欧美在线网站| 久久亚洲国产精品日日av夜夜| 久久久久久**毛片大全| 久久欧美中文字幕| 老牛国产精品一区的观看方式| 久久综合久久综合久久综合| 美女国内精品自产拍在线播放| 久久影院午夜论| 欧美福利专区| 亚洲精品综合久久中文字幕| 亚洲精品久久嫩草网站秘色| 亚洲精品一区二区三区在线观看| 亚洲乱码国产乱码精品精可以看| av不卡在线| 欧美在线观看日本一区| 久久综合999| 欧美日韩亚洲系列| 国产精品永久免费在线| 国内精品一区二区三区| 亚洲国产天堂网精品网站| 一区二区三区四区五区视频| 午夜精品影院| 久久久久久久久久码影片| 欧美高清视频在线播放| 在线视频一区观看| 欧美一区网站| 欧美成人免费大片| 国产精品夜夜嗨| 伊人男人综合视频网| 一区二区三区免费网站| 欧美中文在线观看| 亚洲第一精品电影| 亚洲一区免费视频| 久久夜色精品| 国产精品永久免费视频| 亚洲精品国产系列| 久久精品国产第一区二区三区最新章节| 玖玖玖国产精品| 亚洲免费大片| 久久先锋影音| 国产欧美日韩视频一区二区三区| 在线观看成人一级片| 亚洲天堂久久| 欧美激情亚洲一区| 欧美一区二区三区婷婷月色 | 亚洲在线国产日韩欧美| 鲁大师成人一区二区三区| 国产精品羞羞答答| 亚洲精品在线视频观看| 久久嫩草精品久久久精品一|