Opening a file without overwriting it!
Hi
I have been searching for a solution for this for ages but could not find anything:
I have a binary file which I want to open and modify a value. However when I use something like:
ofstream outfile(filename,ios::out|ios::binary);
the code overwrites the file.
What should I be using so I don't overwrite the existing file?
I am using Visual C++ v6.
Cheers
Robbie
Re: Opening a file without overwriting it!
Add ios::in .. that will prevent file truncation (but the file must exist).
Then seekp() to the spot you want to overwrite.
Code:
ofstream outfile(filename,ios::in|ios::out|ios::binary);
Re: Opening a file without overwriting it!
You could use the ios::app mode if you want to append data to the end of an existing file.
- petter
Re: Opening a file without overwriting it!
Cheers Philip, I will try that tonight.
Re: Opening a file without overwriting it!
use
ios::app...
That shud solve your problem..