title: How to copy the contents of std::vector to c-style static array,safely?
body: <p>I need to manipulate data in fixed array involving mid insertion.
  Rather than using memcpy,etc. I want to use vector. I have problem when I want
  to copy the vector elements back to the c-style array.
  Here's the code:</p>
  
  <pre><code>void tryvector()
  {
      using namespace std;
      const int MAX_SIZE=16;
      BYTE myarr[MAX_SIZE]={0xb0,0x45,0x47,0xba,0x11,0x12, 0x4e};
      vector&lt;BYTE&gt; myvec (myarr, myarr+MAX_SIZE);
      vector&lt;BYTE&gt;::iterator it;
  
      printf("myarr pre :");
      for(int i=0;i&lt;MAX_SIZE;++i){
          printf("%02x ", myarr[i]) ;   
  
      }
  
      printf("\nmyvec pre :")
      for(it=myvec.begin(); it&lt;myvec.end();++it){
         cout&lt;&lt;hex&lt;&lt;static_cast&lt;int&gt;(*it)&lt;&lt;" ";
  
      }
  
      it = myvec.begin()+ 3;
      myvec.insert(it,0x5f);
      printf("\nmyvec post:");
      for(it=myvec.begin(); it&lt;myvec.end();++it){
         cout&lt;&lt;hex&lt;&lt;static_cast&lt;int&gt;(*it)&lt;&lt;" ";
  
  
      }
  
      copy(myvec.begin(), myvec.end(), myarr); //???
      printf("\nmyarr post:");
      for(int i=0;i&lt;MAX_SIZE;++i){
          printf("%02x ", myarr[i]) ;   
  
      }
  
  }
  </code></pre>
  
  <p>I'm using vs 2005.
  Here's the warning:<br/></p>
  
  <pre><code>warning C4996: 'std::_Copy_opt' was declared deprecated
  1&gt;        c:\program files\microsoft visual studio 8\vc\include\xutility(2270) : see      declaration of 'std::_Copy_opt'
  1&gt;        Message: 'You have used a std:: construct that is not safe. See documentation on how to use the Safe Standard C++ Library'
  1&gt;        c:\documents and settings\mhd\my documents\tesvector.cpp(50) : see reference to function template instantiation '_OutIt  std::copy&lt;std::_Vector_iterator&lt;_Ty,_Alloc&gt;,BYTE*&gt;(_InIt,_InIt,_OutIt)' being compiled
  1&gt;        with
  1&gt;        [
  1&gt;            _OutIt=BYTE *,
  1&gt;            _Ty=BYTE,
  1&gt;            _Alloc=std::allocator&lt;BYTE&gt;,
  1&gt;            _InIt=std::_Vector_iterator&lt;BYTE,std::allocator&lt;BYTE&gt;&gt;
  1&gt;        ]
  </code></pre>
  
  <p>When I run it , I got the following run-time error:</p>
  
  <pre><code>
      Run-Time Check Failure #2 - Stack around the variable 'myarr' was corrupted.
  </code></pre>
  
  <p>Please note that I  use vector instead list or deque because
  the 'middle insertion' like the code above is juat a particular problem.
  It will happen less than 'inserting at the end' and
  'random access of element'.
  <br/>
  Any solution ?</p>
  
  <p>Any answer that resembles:"You use c++, drop the c style array implementation. 
  Use only vector for all array implementation" is not really helpful.</p>
  
  <p>Thanks.</p>