title: Copying an array into a std::vector
body: <p>I was searching about this topic and I found many ways to convert an array[] to an std::vector, like using:</p>
  
  <pre><code>assign(a, a + n)
  </code></pre>
  
  <p>or, direct in the constructor:</p>
  
  <pre><code>std::vector&lt;unsigned char&gt; v ( a, a + n );
  </code></pre>
  
  <p>Those solve my problem, but I am wondering if it is possible (and correct) to do:</p>
  
  <pre><code>myvet.resize( 10 );
  memcpy( &amp;myvet[0], buffer, 10 );
  </code></pre>
  
  <p>I am wondering this because I have the following code:</p>
  
  <pre><code>IDiskAccess::ERetRead nsDisks::DiskAccess::Read( std::vector&lt; uint8_t &gt;&amp; bufferRead, int32_t totalToRead )
  {
      uint8_t* data = new uint8_t[totalToRead];
      DWORD totalRead;
      ReadFile( mhFile, data, totalToRead, &amp;totalRead, NULL );
      bufferRead.resize( totalRead );
      bufferRead.assign( data, data + totalRead );
      delete[] data;
  
      return IDiskAccess::READ_OK;
  }
  </code></pre>
  
  <p>And I would like to do:</p>
  
  <pre><code>IDiskAccess::ERetRead nsDisks::DiskAccess::Read( std::vector&lt; uint8_t &gt;&amp; bufferRead, int32_t totalToRead )
  {
      bufferRead.resize( totalToRead );
      DWORD totalRead;
      ReadFile( mhFile, &amp;bufferRead[0], totalToRead, &amp;totalRead, NULL );
      bufferRead.resize( totalRead );
  
      return IDiskAccess::READ_OK;
  }
  </code></pre>
  
  <p>(I have removed the error treatment of the ReadFile function to simplify the post).</p>
  
  <p>It is working, but I am affraid that it is not safe. I believe it is ok, as the memory used by the vector is continuous, but I've never seen someone using vectors this way. </p>
  
  <p>Is it correct to use vectors like this? Is there any other better option?</p>