Reverse Iterators |
Reverse iterators are just like regular iterators, except they traverse a collection backward instead of forward. Every first-class container supports the following functions for obtaining a reverse iterator positioned at an extremity.
reverse_iterator
rbegin()const_reverse_iterator
rbegin() constconst
reverse iterator positioned at the last read-only item in the collection.reverse_iterator
rend()const_reverse_iterator
rend() constconst
reverse iterator positioned immediately before the first read-only item in
the collection. The following example uses a
reverse iterator for iterating backward through a vector
of strings.
#include <iostream>
#include <vector>
void
main()
{
vector< char* > v; // Vector of character strings.
v.push_back( "zippy" );
v.push_back( "motorboy" );
vector< char* >::reverse_iterator i;
for ( i = v.rbegin(); i != v.rend(); ++i )
cout << *i << "\n";
}
motorboy
zippy
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.