title: Read binary file into vector of uint32_t
body: <p>There's a binary file <code>words.bin</code> containing multiple 4 byte integers. I want to read them from the file into a <code>std::vector</code> of corresponding size, which is <code>uint32_t</code>. Here's what I've tried first:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;fstream&gt;
  #include &lt;iterator&gt;
  #include &lt;vector&gt;
  #include &lt;cstdint&gt;
  
  int main(int argc, char* argv[])
  {
      std::ifstream f("words.bin", std::ios::in | std::ios::binary);
      std::vector&lt;uint32_t&gt; wordvec(std::istreambuf_iterator&lt;uint32_t&gt;{f}, {});
  
      return 0;
  }
  </code></pre>
  
  <p>However, I get this error message:</p>
  
  <pre class="lang-none prettyprint-override"><code>u32vec.cpp: In function 'int main(int, char**)':
  u32vec.cpp:9:71: error: no matching function for call to 'std::istreambuf_iterator&lt;unsigned int&gt;::istreambuf_iterator(&lt;brace-enclosed initializer list&gt;)'
       std::vector&lt;uint32_t&gt; wordvec(std::istreambuf_iterator&lt;uint32_t&gt;{f}, {});
  </code></pre>
  
  <p>If I change both <code>uint32_t</code> to <code>char</code>, it does work, but this is not what I want.</p>
  
  <p>My second try was writing the curly bracket notation explicitly, but then accessing the methods of <code>std::vector</code> gives a syntax error. This is the code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;fstream&gt;
  #include &lt;iterator&gt;
  #include &lt;vector&gt;
  #include &lt;cstdint&gt;
  
  int main(int argc, char* argv[])
  {
      std::ifstream f("words.bin", std::ios::in | std::ios::binary);
      std::vector&lt;uint32_t&gt; wordvec(std::istreambuf_iterator&lt;uint32_t&gt;(f), std::istreambuf_iterator&lt;uint32_t&gt;());
  
      wordvec.at(0);
  
      return 0;
  }
  </code></pre>
  
  <p>And this is the compiler output:</p>
  
  <pre class="lang-none prettyprint-override"><code>u32vec.cpp: In function 'int main(int, char**)':
  u32vec.cpp:11:13: error: request for member 'at' in 'wordvec', which is of non-class type 'std::vector&lt;unsigned int&gt;(std::istreambuf_iterator&lt;unsigned int&gt;, std::istreambuf_iterator&lt;unsigned int&gt; (*)())'
       wordvec.at(0);
               ^~
  </code></pre>
  
  <p>This is the output of <code>g++ --version</code>:</p>
  
  <pre class="lang-none prettyprint-override"><code>g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
  Copyright (C) 2018 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>