How to overwrite a byte in a file without clearing the entire file? Note that I don't want to insert additional bytes but rather overwrite a byte at a certain offset.
I have tried the following code to write a byte at some offset. However this clears everything after the specified offset which is not what I want.
#include <fstream>
int main()
{
std::ofstream ofs {"foo", std::ios::binary};
ofs.seekp(0x2);
ofs.put(0x7);
}
In general people on SO seem to suggest reading the entire file then changing it in memory and then writing it out again. However that seems too much work to just change a single byte.
Is it not possible to overwrite a single byte in-place?