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

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -