reverse_iterator::operator++
reverse_iterator加入到上一個項目。
reverse_iterator<RandomIterator>& operator++( );
reverse_iterator<RandomIterator> operator++( int );
傳回值
第一個運算子會傳回preincremented reverse_iterator 和第二個, postincrement運算子,傳回已加入的 reverse_iterator的複本。
備註
此成員函式,如果 reverse_iterator 滿足雙向 Iterator,的需求可能只能透過取得。
範例
// 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;
}
需求
標題: <iterator>
命名空間: std