title: std::iterator, pointers and VC++ warning C4996
body: <pre><code>int *arr = (int*) malloc(100*sizeof(int));
  int *arr_copy = (int*) malloc(100*sizeof(int));
  srand(123456789L);
  for( int i = 0; i &lt; 100; i++) {
      arr[i] = rand();
      arr_copy[i] = arr[i];
  }
  
  // ------ do stuff with arr ------
  
  // reset arr...
  std::copy(arr_copy, arr_copy+100,  arr);
  </code></pre>
  
  <p>while compiling this I get this warning for <code>std::copy()</code>:</p>
  
  <pre><code>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2227):
  warning C4996: 'std::_Copy_impl': Function call with parameters that may be
  unsafe - this call relies on the caller to check that the passed values are 
  correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See 
  documentation on how to use Visual C++ 'Checked Iterators'
  </code></pre>
  
  <p>I know how to disable/ignore the warning, but is there is a simple one liner solution to make a "checked iterator" out of an unchecked pointer? Something like (I know cout is not an unchecked pointer like int*, but just e.g.):</p>
  
  <pre><code>ostream_iterator&lt;int&gt;  out(cout," ");
  
  std::copy(arr_copy, arr_copy+numElements,  out);
  </code></pre>
  
  <p>I don't want to write a whole new specialized <code>class my_int_arr_output_iterator : iterator...</code>. But can I use one of the existing iterators?</p>
  
  <p>---edit---</p>
  
  <p>As there are many many questions abt my usage of c-style-arrays and malloc instead of STL containers, let me just say that I'm writing a small program to test different sorting algorithms' performance and memory usage. The code snippet you see above is a specialized (original code is template class with multiple methods, testing one algorithm for different number of elements in arrays of different types) version specific to the problem.</p>
  
  <p>In other words, I do know how to do this using STL containers (vector) and their iterators (vector::begin/end). What I didn't know is what <strong>I asked</strong>.</p>
  
  <p>Thanks though, hopefully someone else would benefit from the answers if not me.</p>