Do you want something like
fstream fout( "hello.txt", fstream::in | fstream::out | fstream::binary ); fout.seek( offset ); fout.write( "####", 4 );
fstream::app tells it to move to the end of the file before each output operation, so even if you are explicitly looking for a position, the recording location will be forced to end when you execute write() (this is seekp( 0, ios_base::end ); ).
Wed http://www.cplusplus.com/reference/iostream/fstream/open/
One more note: if you opened the file with fstream::app , tellp() should return the end of the file. Therefore, seekp( pos + 5 ) should try to go beyond the current position of the file.
Rob k source share