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::nocreate2.判断文件状态
VC++6.0:
f.is_open() 判断文件是否打开。f.eof() 判断是否到达文件尾。标准C++:
可直接通过
if(f)判断文件是否存在、是否到达文件尾;VC++6.0中可能因为无返回数据,因此不支持该方法。
本文对比了VC++6.0与标准C++中关于fstream库的不同之处,包括头文件引入方式、文件打开行为及文件状态判断等特性,对于理解不同编译环境下文件操作的行为差异具有参考价值。
1174

被折叠的 条评论
为什么被折叠?



