C++ 文件操作的问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 09:54:41
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
无法使用ios::noreplace和ios::nocreate
但是如果第一行改成#include<iostream.h>就可以了,请问这是为什么?

ios::noreplace和ios::nocreate 在标准是不存在的,这是微软自己定义的一套东西。你最好这样子写:

ifstream file(
filename.c_str()
#ifdef _MSC_VER
, ios::in | ios::nocreate
#endif
);