首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

昨天看到的帖子,结果被楼主给结贴了,该怎么解决

2012-05-04 
昨天看到的帖子,结果被楼主给结贴了C/C++ code大家早上好, 昨天看到一个帖子,有三个小问题啊,望指教啊。 #i

昨天看到的帖子,结果被楼主给结贴了

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看了, 没有看到 关于区别的说法。


[解决办法]
探讨
1楼, 代码就是那个,不是有了吗?

[解决办法]
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进制不会像文本流那样随便处理一些空白字符。

热点排行