|

楼主 |
发表于 2020-12-16 23:45:02
|
显示全部楼层
我想建立一个既可以输入又可以输出的文件流,这样就可以不必建立ifstream和ofstream,不知道该怎么做?下面这个程序运行时没有建立a.txt文件,不知道又哪错了。
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{fstream file("a.txt",ios::in|ios::out);
string s1,s2;
s1="abcd 1234\n";
file<<s1; //写不进a.txt中
file>>s2;
cout<<"s2="<<s2<<endl;//s2为空
file.close();
getch();
return 0;
}
|
|