C++文件流的问题

webrolling 2003-08-22 08:41:25
文件流类的成员函数eof(),为什么在文件已经结束的时候检测不到。而非得等到读取文件失败的时候才有反映。这样的问题怎么解决?
...全文
43 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
atEleven 2003-08-31
  • 打赏
  • 举报
回复
那stl中的iterator全都是这个样子的.

没错误发生怎么知道自己是错了?
BinaryWorld 2003-08-31
  • 打赏
  • 举报
回复
我觉得大家的讨论有够无聊啊。

如果不知道现在读入的是-1,怎么确定文件结束啊??这都是本来应该的东西好不好。
webrolling 2003-08-30
  • 打赏
  • 举报
回复
我觉得eof()有问题,它的工作过程好象是:读入一个字符,如果无法读取则退出函数并返回false,但是这就意味着在文件结束时,它会多读取一个字符,而就是这个字符会带来很多麻烦。大家有没有好的建议啊?还是我理解的eof()的工作过程不对?
ShiChao 2003-08-27
  • 打赏
  • 举报
回复
文件已经结束是什么意思?
你可以这样读文件
while (!fin.eof()) // dont stop until touch EOF
{
fin.read(buff, buff_size); // 好像参数是这样的,记不清了
}
webrolling 2003-08-27
  • 打赏
  • 举报
回复
这是c里面的
我用的是c++啊
lybapple 2003-08-22
  • 打赏
  • 举报
回复
CFile::Read
virtual UINT Read( void* lpBuf, UINT nCount );
throw( CFileException );

Return Value

The number of bytes transferred to the buffer. Note that for all CFile classes, the return value may be less than nCount if the end of file was reached.

Parameters

lpBuf

Pointer to the user-supplied buffer that is to receive the data read from the file.

nCount

The maximum number of bytes to be read from the file. For text-mode files, carriage return–linefeed pairs are counted as single characters.

Remarks

Reads data into a buffer from the file associated with the CFile object.

Example

//example for CFile::Read
extern CFile cfile;
char pbuf[100];
UINT nBytesRead = cfile.Read( pbuf, 100 );

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧