fstream在VC++6.0与标准C++中的差异

来源:互联网 发布:传奇世界h5源码 编辑:程序博客网 时间:2024/06/12 23:53

VC++6.0和标准C++在fstream方面的差异(未完待续)

1.头文件

VC++6.0:
#include<fstream.h>
标准C++
#include<fstream>using namespace std;

2.方法特性

1.只读特性

VC++6.0:

fstream f;f.open("example.txt",ios::in);
读取时如果文件example.txt不存在,会自动创建example.txt。
fstream f;f.open("example.txt",ios::in|nocreate);
读取时如果文件example.txt不存在,会自动创建example.txt。

标准C++:

<pre name="code" class="cpp">fstream f;f.open("example.txt",ios::in);
读取时如果文件example.txt不存在,会自动创建example.txt。同时移除了
ios::nocreate

2.判断文件状态

VC++6.0:

f.is_open()
判断文件是否打开。
f.eof()
判断是否到达文件尾。

标准C++:

可直接通过
if(f)
判断文件是否存在、是否到达文件尾;VC++6.0中可能因为无返回数据,因此不支持该方法。




1 0
原创粉丝点击