I try to replace data in binary file using C++ and fstream library. Is it possible to do that with this library? I would like to change one byte of file in address: 0xB07 to 1.
I have written the following code snippet:
...
int address = 0xB07;
char * toChange = new char('0');
std::ifstream input(filename, std::ios::binary);
input.seekg(address);
input.read(toChange, 1);
input.close();
*toChange = (char)0x01;
std::ofstream output(filename, std::ios::binary);
output.seekp(address);
output.write(toChange, 1);
output.close();
...
I have tried many versions of this code and I still can't understand why the byte doesn't change.