reverse_iterator::operator++
Increments the reverse_iterator to the previous element.
reverse_iterator<RandomIterator>& operator++( );
reverse_iterator<RandomIterator> operator++( int );
Return Value
The first operator returns the preincremented reverse_iterator and the second, the postincrement operator, returns a copy of the incremented reverse_iterator.
Remarks
This member function may only be used if the reverse_iterator satisfies the requirements for a bidirectional iterator.
Example
// reverse_iterator_op_incr.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for ( i = 1 ; i < 6 ; ++i )
{
vec.push_back ( 2 * i - 1 );
}
vector <int>::iterator vIter;
cout << "The vector vec is: ( ";
for ( vIter = vec.begin( ) ; vIter != vec.end( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
vector <int>::reverse_iterator rvIter;
cout << "The vector vec reversed is: ( ";
for ( rvIter = vec.rbegin( ) ; rvIter != vec.rend( ); rvIter++)
cout << *rvIter << " ";
cout << ")." << endl;
// Initializing reverse_iterators to the last element
vector <int>::reverse_iterator rVPOS1 = vec.rbegin( );
cout << "The iterator rVPOS1 initially points to the first "
<< "element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
rVPOS1++; // postincrement, preincrement: ++rVPSO1
cout << "After incrementing, the iterator rVPOS1 points\n"
<< " to the second element in the reversed sequence: "
<< *rVPOS1 << "." << endl;
}
The vector vec is: ( 1 3 5 7 9 ).
The vector vec reversed is: ( 9 7 5 3 1 ).
The iterator rVPOS1 initially points to the first element
in the reversed sequence: 9.
After incrementing, the iterator rVPOS1 points
to the second element in the reversed sequence: 7.
Requirements
Header: <iterator>
Namespace: std