   STL vector problem
  I want to make a memcpy from an stl vector to an integer pointer.I saw a member of the vector template called "pointer".So I tried to use vec.pointer as the source of the copy only to get the error:function-style cast'' : illegal as right side of ''.'' operatorHow can I do what I want? 
  &vec[0] points to the first element ;  So I can do the copy directly from the vec object, is that what you mean. Because I need a pointer, not the first element. ;  You should be able to do something like this:vector<int> vec;for(int i = 0; i < 10; ++i)vec.push_back(i);int* int_array = new int[vec.size()];memcpy(int_array, vec.begin(), vec.size());for(i = 0; i < vec.size(); ++i)cout << vec << "   " << int_array &lt;&lt; endl;<br><br>delete[] int_array;<br><br> </pre> <br><br>I have not tested it, but the data in a vector is guaranteed to be contiguous in memory just as an array is.  Also, I don''t know of any pointer member in the STL vector class.  begin() will give you a reference to the first element, however.  </i>  ;  arghh, sorry forgot about the  thing.  That line near the end should read<br><br>cout &lt;&lt; vec &lt;&lt; …<br><br>   ;  oops! another correction:memcpy(int_array, vec.begin(), vec.size()*sizeof(int));Before it was just copying 10 bytes!  Not what we want. ;  Ill just have to as why you don''t usestd::copy( vec.begin(), vec.end(), destination_pointer); ;  The destination is the vector, and I need to get the pointer of to that memory. That is the problem.   [edited by - Mr Cucumber on July 31, 2003 11:03:13 AM];  Oh you didn''t say that before.  You said copy from the vector to an integer pointer.  You can just do this then, it is almost the same code as before:vector<int> vec;int* int_array = new int[10];for(int i = 0; i < 10; ++i)int_array = i;<br><br>vec.resize(10);<br>memcpy(vec.begin(), int_array, 10*sizeof(int));<br><br>cout &lt;&lt; vec.size() &lt;&lt; endl;<br>for(i = 0; i &lt; 10; ++i)<br>cout &lt;&lt; vec &lt;&lt; &quot;   &quot; &lt;&lt; int_array &lt;&lt; endl;<br><br>delete[] int_array;<br> </pre> <br><br>The resize() is the important bit that was added.  And of course the destination and sorce in the memcpy are switched.   ;quote:Original post by Mr Cucumber  So I can do the copy directly from the vec object, is that what you mean. Because I need a pointer, not the first element.   A pointer to the first element is equivalent to a pointer to the beginning of the storage used by the vector. So use &vec[0].MSN 