I am reading binary data from a file, however reading one byte at a time gives expected results, while reading anymore than one byte at a time does not. Reading one at a time:
void readFile(){
std::ifstream in;
in.open("file.bin", std::ios:binary);
uint8_t byte1;
uint8_t byte2;
in.read(reinterpret_cast<char *>(&byte1), sizeof(byte1));
in.read(reinterpret_cast<char *>(&byte2), sizeof(byte2));
std::cout << std::bitset<8>(byte1) << std::bitset<8>(byte2);
}
This produces the expected output of
0000101000000110
Reading two at a time:
void readFile(){
std::ifstream in;
in.open("file.bin", std::ios:binary);
uint16_t twobytes;
in.read(reinterpret_cast<char *>(&twobytes), sizeof(twobytes));
std::cout << std::bitset<16>(twobytes);
}
Produces unexpected output of
0000011000001010