C++ examples for STL:iterator
Using non-const iterators with a vector
#include <cinttypes> #include <iostream> #include <vector> using namespace std; int main(int arcg, char* argv[]) { using IntVector = vector<int32_t>; using IntVectorIterator = IntVector::iterator; IntVector myVector(5, 0);/*from www.j a v a 2 s . c o m*/ int32_t value{ 0 }; for (IntVectorIterator iter = myVector.begin(); iter != myVector.end(); ++iter) { *iter = value++; } for (IntVectorIterator iter = myVector.begin(); iter != myVector.end(); ++iter) { cout << "The value is: " << *iter << endl; } return 0; }