|
-
June 26th, 2007, 11:37 AM
#1
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: ut|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
-
June 26th, 2007, 11:58 AM
#2
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);
-
June 26th, 2007, 12:00 PM
#3
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
-
June 26th, 2007, 12:42 PM
#4
Re: Opening a file without overwriting it!
Cheers Philip, I will try that tonight.
-
June 27th, 2007, 09:18 PM
#5
Re: Opening a file without overwriting it!
use
ios::app...
That shud solve your problem..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|