I know how to read and write a complete struct with fstream. But just for curiosity, is there a way to access (read or write) a variable directly? I have never seen somebody doing this.
aStruct * dummyStruct = 0;
int num = 7;
File.seekp(streamPosition, ios::beg);
File.seekp((unsigned long long)&(dummyStruct->aVariable), ios::cur);
File.write(reinterpret_cast<const char*>(&num), sizeof(num));
Has anybody done something like this?
offsetof
instead for theseekp
call, but it's certainly doable. And if you only want to write that single variable (and the variable is the exact same size as in the structure) then I see no problem with this. – Joachim Pileborg May 26 '13 at 18:25