码迷,mamicode.com
首页 > 其他好文 > 详细

ifstream

时间:2017-10-14 21:20:57      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:没有   一点   height   fstream   nbsp   lin   eve   buffer   style   

eof() 这个东西是返回文件是否达到尾部。

           在读取错误的时候才会触发。

           这点要小心,如果写在while(eof) 即使到了文件尾部,

           但并没有读取错误,很有可能再次进入循环,然后出现读取错误

.get()

.getline() 

这两个因为重载了,get的种类,比getline多几个 

          

istream& getline (char* s, streamsize n );
istream& getline (char* s, streamsize n, char delim );
single character (1)
int get();
istream& get (char& c);
c-string (2)
istream& get (char* s, streamsize n);
istream& get (char* s, streamsize n, char delim);
stream buffer (3)
istream& get (streambuf& sb);
istream& get (streambuf& sb, char delim);

记住一点:啥叫c-string,那个n是c-string的大小,因为c-string最后一个总是为‘\0’,所以实际上只是读入了 n-1个char

还有一点:get 不丢任何东西,getline 是要丢东西的

 

ifstream

标签:没有   一点   height   fstream   nbsp   lin   eve   buffer   style   

原文地址:http://www.cnblogs.com/infoo/p/7668300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!