title: Wrong use of std::copy?
body: <p>Here is a simple test program that illustrates the problem I faced:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;inttypes.h&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  typedef unsigned char Byte;
  
  int main( )
  {
      uint32_t ui32 = 12;
      size_t sizeofUi32 = sizeof ui32;
      cout &lt;&lt; "sizeofUi32: " &lt;&lt; sizeofUi32 &lt;&lt; endl;
      vector&lt;Byte&gt; v(10);
      std::copy(&amp;ui32, &amp;ui32 + sizeof ui32, &amp;v[4]);
  
      uint32_t result = 0;
      std::copy(&amp;v[4], &amp;v[4] + sizeof ui32, &amp;result);
  
      cout &lt;&lt; "Result: " &lt;&lt; result &lt;&lt; " sizeofUi32: " &lt;&lt; sizeofUi32 &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>sizeofUi32: 4    
  Result: 12 sizeofUi32: 17179869184
  </code></pre>
  
  <p>I thought this issue might be due to std::copy accepting iterators not pointers, but from what I got in SO <a href="https://stackoverflow.com/questions/2728190/how-are-iterators-and-pointers-related">here</a>, </p>
  
  <blockquote>
    <p>a pointer IS an iterator</p>
  </blockquote>
  
  <p>So there must be a simple issue with my sample code, that I' missing. But I can't spot it.
  Could you please explain, what's wrong here?</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>So from the answers I got the idea, that to deserialize a vector of bytes, if I know the right order and types of stored data in vector, I can avoid using std::copy and just assign vector values to variables of proper types. It works, but is it safe?</p>
  
  <pre><code>uint32_t a = v[4];
  uint8_t b = v[8];
  </code></pre>