1

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

2 Answers2

2

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); 
Joni
  • 108,737
  • 14
  • 143
  • 193
0

http://www.cplusplus.com/reference/cstdio/fseek/

try using fseek(). link above is documentation

sublime.Hat
  • 51
  • 10