My machine works in little endian. I have to read using C++ std::ios::binary some files with big endian encoding. Is there any standard and fast way for doing it? For the moment, after having read raw data I do the following:
(reading a double)
char raw [8];
double d = 0; //maybe initialization is not needed
file.read(raw,8); //4 for an int
for(int k = 0; k < 8; k++) {
memcpy((void *)(((char *)(&d))+k), (const void *)(raw+j+7-k), 1);
}
(reading an integer)
char raw [4];
file.read(raw,4); //4 for an int
int i = (raw[j] << 24) | (raw[j+1] << 16) | (raw[j+2] << 8) | raw[j+3];