I am trying to read a file as binary using fstream into a structure. This file contains normally aligned values as well as 12 and 9 bit values following this schematic:
My structure looks like this:
struct sFile{
unsigned char padding1[765]; //other values before this
char identifier[2]; //checking if we're in the right spot
unsigned strID: 9;
unsigned strValue : 12;
unsigned eneID : 9;
unsigned eneValue : 12;
unsigned dexID : 9;
unsigned dexValue : 12;
unsigned vitID : 9;
unsigned vitValue : 12;
}
And I'm trying to read to it this way
sFile saveFileStruct;
[...]
saveFile.read((char*)&saveFileStruct, sizeof(saveFileStruct));
I am pretty sure I'm doing something wrong since I get slightly shifted values from what they are supposed to be while the identifier is correct. I would like to know what I am doing wrong here or if there is a better way of doing it.
Thank you.