title: std::ifstream in binary mode and locale in C++
body: <p>A comment by James Kanze on <a href="https://stackoverflow.com/questions/18398167/how-to-copy-a-txt-file-to-a-char-array-in-c/18398230#18398230">How to copy a .txt file to a char array in c++</a> 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:</p>
  
  <ul>
  <li>open the file in binary mode,</li>
  <li>ensure that the file is imbued with the "C" locale.</li>
  </ul>
  
  <p>In code, I'm guessing that means:</p>
  
  <pre><code>std::ifstream in(filename, ios_base::binary);
  in.imbue(std::locale("C"));
  </code></pre>
  
  <p>Is that really necessary? More specifically, why would the locale have any impact when the file is opened in binary mode?</p>
  
  <p>Note that what I am trying to do is more or less what the above mentioned question was about:</p>
  
  <pre><code>std::string contents(std::istreambuf_iterator&lt;char&gt;(in), std::istreambuf_iterator&lt;char&gt;());
  </code></pre>