1. Is the integer you want to read 8 bits, 16 bits, or 32 bits, unsigned or signed? Need to use the corresponding type, 8 bits are char, 16 bits are short, and 32 bits are int. If you use int, you actually read four bytes at a time and treat it as a 32-bit integer. If you want to read an octet (unsigned type), you should use unsigned char and then convert it to int:
char * base = (char*)MapViewOfFile(...)
int first =(int)base[0];
cout & lt& ltfirst & lt& ltendl
2. Small-end and big-end formats. Windows is a small format, such as the integer 0x 1 1223344, which is stored in memory in the following order:
44 33 22 1 1
That is, the low byte is at the low address and the high byte is at the high address.
Other systems use big-end format, and the storage order in memory is 1 1 22 33 44. Migrating data from these systems requires reversing the byte order.
3. Align the boundaries. If the specified offset is not aligned with the boundary of 16 bit or 32 bit, there will be a problem in reading 16 bit or 32 bit. Reading 8 bits does not have this problem.