You have to open the file in read-write mode to prevent the call to open
from truncating it:
test.open(filedestination, ios::binary | ios::in | ios::out);
문제
I want to write an info to binary file's last 32 characters. But when i call my writeInfo function, it deletes the whole content. I can read the data before i write, but after i write with this function, it deletes the whole content, instead of writing.
void Info::writeInfo(char *filedestination)
{
ofstream test;
test.open(filedestination, ios::binary);
test.seekp(-32, ios::end); // not sure about seekp
test.write(info, 31);
test.close();
}
Hope you can help, thank you
해결책
You have to open the file in read-write mode to prevent the call to open
from truncating it:
test.open(filedestination, ios::binary | ios::in | ios::out);
다른 팁
http://www.cplusplus.com/reference/cstdio/fseek/
try using fseek(). link above is documentation