昨天看到的帖子,结果被楼主给结贴了
- C/C++ code
大家早上好, 昨天看到一个帖子,有三个小问题啊,望指教啊。 #include "stdafx.h"#include <fstream>#include <iostream>using std::ifstream;using std::cout;int main(){ int n=0; char ch; ifstream ifile("12113.txt", ifstream::in|ifstream::binary); if(ifile.fail()) { cout<<"文件打开失败"; return 0; } if( ifile.eof()) n=2345; cout<<n; return 0;}这段代码 是楼主提供的,其中了使用了cout对象,fstream中包含了iostream这个头文件,结果使用cout的时候,还是要包含iostream,不是fstream中已经有了吗 ,这是怎么回事???fstream继承iostream,所以要包含其头文件,这是必须的。另外: 发现对一个win32中的 空文件 进行eof函数操作,返回flase的。。既然是空文件,那么返回true,是 毫无疑问的, 结果是false.第三个问题: 所谓的二进制方式打开,倒是是什么意思? 与不是二进制方式打开,有什么区别???在msdn看了, 没有看到 关于区别的说法。[解决办法]
[解决办法]
- C/C++ code
Return ValuesThe feof function returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file. There is no error return.
[解决办法]
1.没看到有包含iostream
2.如果你是用其作为while循环的条件建议直接用类似cin>>s作为循环判断条件
3.2进制不会像文本流那样随便处理一些空白字符。