title: Write set of integers to std::ofstream and be able to read them back
body: <p>I need to write a bunch of unsigned integers to <code>std::ofstream</code> in binary mode:</p>
  
  <pre><code>std::ofstream f;
  f.open("some path", std::ios::out | std::ios::binary);
  // some loop
  {
    unsigned int k = get_k(); // may product numbers from 0 to 65535
    f &lt;&lt; k;
  }
  f.close();
  </code></pre>
  
  <p>They are written to the output file "as is" w/o any delimiter. So when I'm trying to read them back (expecting to get what I wrote) using <code>std::ifstream</code> I get very strange values. What I'm doing wrong?</p>
  
  <p>Or I should to put <code>' '</code> (space) to the stream after any added number to separate them?</p>
  
  <p>Thanks.</p>