My binary file looks like this.
00000000: 0000 0803 0000 ea60 0000 001c 0000 001c
00000010: 0000 0000 0000 0000 0000 0000 0000 0000
left co
You have two issues:
Insuring you read the bytes you intend (no fewer, no more) from the stream.
I'd recommend this syntax:
uint32_t a;
inFILE.read(reinterpret_cast
Insure you're interpreting those bytes with the correct byte order.
Q: If you're on a PC, your CPU is probably little endian. Do you know if your data stream is also little-endian, or is it big endian?
If the data is big-endian, I'd consider the standard networking functions to accomodate byte order: ntohl()
, etc: http://www.retran.com/beej/htonsman.html
ALSO:
Follow Hcorg's and Daniel Jour's advice: don't forget about the "open mode" parameter, and don't forget to check for "file open" errors.