O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Iterators

Most container classes have iterators supplied with them that allow you to move through the range and obtain successive references to elements contained within it. You’ve seen iterators all through the discussion of the STL algorithms, but they are also available to the programmer.

The main iterators are begin, end, rbegin, and rend. These iterators provide the functionality to specify the end points of the range that you want to examine. You can move through the range of elements without knowing anything else about either the range or the elements.

One example of this uses a for loop that starts at ::begin and goes to ::end, returning the container class type at each step. For example:

for ( element = my_string.begin( ) ; element ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required