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.
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.