[try Beta version]
Not logged in

 
ofstream

Nov 8, 2012 at 8:14am
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!
Nov 8, 2012 at 8:37am
Nov 8, 2012 at 9:47am
from this I understood I should use output.open("test.txt" , iostream::ate);
it still deletes the previous content though
Nov 8, 2012 at 10:58am
Nov 8, 2012 at 11:30am
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
Nov 8, 2012 at 12:03pm
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.
Nov 8, 2012 at 1:07pm
yeah this is working. Thank you!
Topic archived. No new replies allowed.