Chinaunix首页 | 论坛 | 博客
  • 博客访问: 432932
  • 博文数量: 138
  • 博客积分: 4114
  • 博客等级: 上校
  • 技术积分: 1341
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-14 20:41
文章分类

全部博文(138)

文章存档

2014年(1)

2013年(2)

2012年(78)

2011年(13)

2010年(34)

2009年(10)

我的朋友

分类: LINUX

2011-11-07 14:19:20

  1. string line
  2. ifstream inf("file.txt");
  3. while(getline(inf, string))
  4. {
  5.    cout << string << endl;
  6. }
一直不明白  getline的返回值是什么, 为什么可以用来 判断
因为  它的原型是
  1. istream& getline (char* s, streamsize n );
  2. istream& getline (char* s, streamsize n, char delim );
是一个引用,引用不会为空,它应该永远为真阿, 这是怎么实现的?问题先记到这里,
等有机会看源码,看它是怎么实现这个函数的
下面是网上摘过来的
istream&   getline   (istream&   is,   string&   str,   char   delim   =   '\n ');

Reads   characters   from   an   input   stream   into   a   string,  stopping   when   one   of   the   following   things   happens:
An   end-of-file   condition   occurs   on   the   input   stream   When   the   maximum  
 number   of   characters   that   can   fit   into   a   string   have   been   read
When   a   character   read   in   from   the   string   is   equal   to   the   specified  
 delimiter   (newline   is   the   default delimiter);   the   delimiter   character   is  
removed   from   the   input   stream,   but   not   appended   to   the   string.  
The   return   value   is   a   reference   to   the   input   stream.   If  
the   stream   is   tested   as   a   logical   value   (as   in   an  
if   or   while),   it   is   equivalent   to   true   if   the   read  
was   successful   and   false   otherwise   (e.g.,   end   of   file).






阅读(9072) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~