c++11 - how to maintain a pointer pointing to elements of vector? -


 vector<int>vec(n,0);  int* ptr=vec; 

can vector arrays or have have iterators.what want maintain pointer pointing elements of array.

i can think of couple of ways pointer elements of vector.

int* p = &(vec[0]); 

or

int* p = vec.data(); 

however, unless know doing, don't recommend using pointers access elements of vector. use iterators access elements of vector. there not gained , lose preferring use pointers on iterators.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -