<<< Getting information | Index | Iterators are like pointers >>> |
An
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
<<< Getting information | Index | Iterators are like pointers >>> |