ofstream

dorA26 (16)
when opening a file does ofstream deletes its content by default? If so, how do I cancel that? I don't want to use app, because I need to edit the file between the existing characters.

thanks!
JLBorges (1336)
http://stdcxx.apache.org/doc/stdlibug/30-3.html
dorA26 (16)
from this I understood I should use output.open("test.txt" , iostream::ate);
it still deletes the previous content though
Chervil (812)
ios::app
http://www.cplusplus.com/reference/iostream/ofstream/open/
dorA26 (16)
but then I can only add output at the end of the file (that's what I understand at least).. I don't want that
Chervil (812)
Sorry, I misread the question.
This might be better:
fstream fout("test.txt", ios_base::in | ios_base::out | ios_base::ate);
The first time this is run, if the file does not already exist, it will give an error, so you may need alternative logic for that case.
dorA26 (16)
yeah this is working. Thank you!
Registered users can post here. Sign in or register to post.