So here's the class I'm having trouble with (I'm mainly talking about the loadlevel and access functions, but i've included the whole class just in case):
So basically, I'm trying to load a 16 byte bin file, which would be loaded into an array of 4 32bit unsigned integers. The first value should be 0, and the other values should be different than that (I'm too lazy to figure out their exact value); but I get unexpected results:
You can do what ocreus suggested with std::istreams:
1 2 3 4
uint32_t i;
stream.read((char *)&i, sizeof(i));
if (stream.gcount() != sizeof(i))
//We didn't get enough bytes. Maybe we hit EOF or something else went wrong.
The problem with this is that attempting to read your file on a different platform may not work, due to for example different endianness.
You'll want to pick a consistent format:
1 2 3 4 5 6 7
unsignedchar data[4];
stream.read((char *)data, sizeof(data));
if (stream.gcount() != sizeof(data))
//...
uint32_t i = 0;
for (int j = 0; j < 4; j++)
i |= (uint32_t)data[i] << (8 * i);