C++ FAQ Celebrating Twenty-One Years of the C++ FAQ!!!
(Click here for a personal note from Marshall Cline.)
Section 15:
[15.12] How can I open a stream in binary mode?

Use std::ios::binary.

Some operating systems differentiate between text and binary modes. In text mode, end-of-line sequences and possibly other things are translated; in binary mode, they are not. For example, in text mode under Windows, "\r\n" is translated into "\n" on input, and the reverse on output.

To read a file in binary mode, use something like this:

#include <string>
#include <iostream>
#include <fstream>

void readBinaryFile(std::string const& 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, so you won't normally use that when reading binary files.