A comment by James Kanze on How to copy a .txt file to a char array in c++ makes it sound like in order to be sure that a standard string would get the exact binary contents of a file when iterated through by a standard string constructor, one would have to both:
- open the file in binary mode,
- ensure that the file is imbued with the "C" locale.
In code, I'm guessing that means:
std::ifstream in(filename, ios_base::binary);
in.imbue(std::locale("C"));
Is that really necessary? More specifically, why would the locale have any impact when the file is opened in binary mode?
Note that what I am trying to do is more or less what the above mentioned question was about:
std::string contents(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());