how do I seek beyond end of existing file ?
Consider I have test.bin which is 1000 bytes.
Then I run following
std::filebuf fbuf;
fbuf.open("c:\\test.bin", std::ios_base::in | std::ios_base::out | std::ios_base::app | std::ios_base::binary);
fbuf.pubseekoff(10, std::ios_base::end);
fbuf.sputc(1);
fbuf.close();
After running this example I expect new filesize to be 1011 bytes. But instead it adds 0x01 at the end of existing file making it 1001 bytes.
Interestingly though it works the way I want it when it’s new file.
I’m running this on Windows 7 x64 but target platform will be Ubuntu.
You set the
std::ios_base::appflag. This causes all writes to occur at the end of the file. If you want writes to be performed at the current position, you cannot specify this flag when you open the file.