|
|
下面程序建立不了文件,不知道哪里出错了?
只想定义一个fstream类型来完成输入输出的工作.
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
fstream file("a.txt",fstream::in|fstream: ut|fstream::app);
string s1,s2;
if(!file) cerr<<"error"<<endl; //执行了这一句,不知道为什么?
s1="abcd 1234\n";
file<<s1; //写不进a.txt中
file.flush();
file.seekg(0);
file>>s2;
cout<<"s2="<<s2<<endl;//s2为空
file.close();
getch();
return 0;}
没有出现编译错误
程序可以运行,结果是:
error
s2=
[em4] |
|