I need to read a binary file written on little-endian OS. An extraction operator<< does not work on binary files. It seems that a simpleminded implementation along the lines of code below works on Mac OS X running on Intel chips. I just wonder how kosher is it. Would I just need to swap bytes on big-endian machines?
#include <istream>
#include <cstdint>
...
std::stream sfile(path, std::ios::binary);
...
uint32_t iValue;
sfile.read(reinterpret_cast<char *>(&iValue), sizeof(uint32_t));
double dValue;
sfile.read(reinterpret_cast<char *>(&dValue), sizeof(double));