If you are dealing with a small file size, I recommend that reading the entire file is easier. Then work with the buffer and write the entire block again. They show you how to read the block - provided that you fill in the open I / O file from the answer above.
.....
input.seekg (0, ios::end);
int length = input.tellg();
input.seekg (0, ios::beg);
buffer = new char [length];
input.read (buffer,length);
............
output.write(newBuffer, sizeof(newBuffer));
delete buffer;
delete newBuffer;
..........
source
share