overwrite some bytes using ofstream

Hi,
I want to overwrite some bytes of a file, for example
1
2
3
4
5
		ofstream ofs("aa.txt", ios::binary);

		ofs.write("abc", 3);

		ofs.close();

I just need to replace the first 3 bytes, but the file was totally truncated. the other bytes were gone.
is there any simple way to do this? I don't want to read the hole file into buffer then get the replacement done and write back, because the file could be very large.
Have a look at the flags. I expect you'll need to use an append flag.
http://www.cplusplus.com/reference/fstream/fstream/open/
Topic archived. No new replies allowed.