#include <iostream>
#include <fstream>
int main()
{
using namespace std;
/* Open a file and read it*/
ofstream file_obj;
file_obj.open("file1.txt",ios::in| ios::out | ios::app);
if( file_obj.is_open() )
{
printf("\n File opened successfully ");
}
else
{
printf("\n Error occured in opening the file");
}
return 0;
}
它提供输出
打开文件时出错。
但当我删除ios时:工作正常。
为什么这种组合不可能?
答案 0 :(得分:0)
ofstream
类仅用于输出(写入文件) - 因此为“o”。使用fstream
代替 - 这允许输入和输出。