<<< Functions returning a pair | Index | Iterator Pitfalls >>> |
An iterator is an object that provides access to objects stored in STL containers.
Iterators are designed to behave like C++ pointers.
#include <iostream> #include <vector> using namespace std; int main (int argc, char* argv[]) { vector< int > vint( 3 ); // vector with 3 integer numbers vint[ 0 ] = 10; vint[ 1 ] = 20; vint[ 2 ] = 30; // Display elements of the vector: vector< int >::iterator it; for ( it = vint.begin(); it != vint.end(); ++it ) { // Like pointer, iterator is dereferenced to // access the value of the element pointed by it: cout << " " << *it; } return 0; } // Output: 10 20 30
<<< Functions returning a pair | Index | Iterator Pitfalls >>> |