A: Use std::ios::binary.
Some operating systems differentiate among text and binary modes. In text mode, end-of-line sequences and perhaps other things are translated; in binary mode, they are not. For instance, in text mode under Windows, "\r\n" is translated in "\n" on input, & the reverse on output.
To read a file in binary mode, employ something like this:
#include
#include
#include
void readBinaryFile(const std::string& filename)
{
std::ifstream input(filename.c_str(), std::ios::in | std::ios::binary);
char c;
while (input.get(c)) {
...do something with c here...
}
}
Note : input >> c discards leading whitespace, thus you won't normally employ that when reading binary files.