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
Post a Comment