0
<SOLVED> ios::app, or ios::out clearing file data?
Consider a file 'new.txt' with these contents 0 Hello then I run this code(c++): fstream file("new.txt",ios::out); file<<1; file.close(); file.open("new.txt,ios::app|ios::out); file<<"\nBye"; Since I'm using ios::app mode I should be writing to the end of the file. So after I run the code it should be: 1 Hello Bye But instead that's what happens: 1 Bye I have tryed other methods too to write to the end of the file like file.clear(); file.seekg(ios::end); But nothing works as it should... Any suggestions?
2 Answers
+ 4
Aren't you implicitly truncating the file with the first open?
+ 4
Dennis Yeah i figured it out after a lot of testing. I didn't know that ios::out had these consiquencies. Thank you