title: How to read entire stream into a std::vector?
body: <p>I read <a href="https://stackoverflow.com/a/3203502/416274">an answer here</a> showing how to  read an entire stream into a std::string with the following one (two) liner:</p>
  
  <pre><code>std::istreambuf_iterator&lt;char&gt; eos;    
  std::string s(std::istreambuf_iterator&lt;char&gt;(stream), eos);
  </code></pre>
  
  <p>For doing something similar to read a binary stream into a <code>std::vector</code>, why can't I simply replace <code>char</code> with <code>uint8_t</code> and <code>std::string</code> with <code>std::vector</code>?</p>
  
  <pre><code>auto stream = std::ifstream(path, std::ios::in | std::ios::binary);    
  auto eos = std::istreambuf_iterator&lt;uint8_t&gt;();
  auto buffer = std::vector&lt;uint8_t&gt;(std::istreambuf_iterator&lt;uint8_t&gt;(stream), eos);
  </code></pre>
  
  <p>The above produces a compiler error (VC2013):</p>
  
  <blockquote>
    <p>1>d:\non-svn\c++\library\i\file\filereader.cpp(62): error C2440:
    '' : cannot convert from
    'std::basic_ifstream>' to
    'std::istreambuf_iterator>' 1><br>
    with 1>          [ 1>              _Elem=uint8_t 1>          ] 1><br>
    No constructor could take the source type, or constructor overload
    resolution was ambiguous</p>
  </blockquote>