|
I want to create a file stream that can both input and output, so that I don’t need to create ifstream and ofstream. I don’t know what to do? The a.txt file is not created when the following program is running, so I don't know what is wrong.
#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; //Cannot write into a.txt
file>>s2;
cout<<"s2="<<s2<<endl;//s2 is empty
file.close();
getch();
return 0;
} |
|