I want to read and write to text file at the same time. But I have met some problem. Here is my code:
Code:
int main()
{
string t;
fstream f(file,ios::out|ios::in);
f>>t; //read first line of file
f<<"C++"<<endl; //printf C++
f<<"Programming"<<endl; //print Programming
f>>t; //Read file
f.close();
return 0;
}
My text file, for example is: hello \n afternoon \n morning
After run, my text file is no change. and t is just hello in both two cases.
I cannot understand why like that. Help me about this problem,please
thanks