Hello,

I want to edit the contents of a file using fstream, but none of the modes in the fstream constructor work for me.

If I use ios::trunc, then the whole file is deleted - but I want to retain the contents and edit it.
If I use ios::app, then I can only add data to the end of the file - but I want to edit the data in the middle of the file.
If I use ios::ate, then the whole file is deleted again, similar to ios::trunc.

How can I create an fstream object without deleting the contents of the file, whilst still being able to move the pointer arbitrarily around in the file with seekp() (and not just placing it at the end as with ios::app)?

Thanks!