Reputation: 3
I am facing problem while overwriting a file at a particular position in C++. I have opened my file using ios::app|ios::binary
. Then I seek to that position which I want to overwrite. But instead of overwriting it, I append from the end of the file. Any suggestions?
Upvotes: 0
Views: 265
Reputation: 1057
You can open your file with ios::in|ios::out|ios::binary. After that you should use seekp() to seek to the desired position of the file before the write.
Upvotes: 0
Reputation: 129314
You need to specify ios::in
as well as ios::out
. It overwrites if you have only ios::out
(default in ofstream
). As stated ios::app
means data is written to the end of the file, which is not what you want.
Upvotes: 9