<<< Mistakes when using iterators | Index | The iterator abstraction >>> |
Iterators on vectors are random-access.
Other types include forward and bidirectional iterators.
Random-access iterators can be
incremented ++
decremented --
added with integers to give new iterators:
vector<int>::const_iterator iter = v1.begin(); iter += 7; //Now iter points to the 7th element! // This could be expensive, maybe use a list instead? iter = v1.insert( iter, 3 ); iter = v1.insert( iter, 8 );
<<< Mistakes when using iterators | Index | The iterator abstraction >>> |