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中可能因为无返回数据,因此不支持该方法。