reverse_iterator::operator--
reverse_iterator 減到上一個項目。
reverse_iterator<RandomIterator>& operator--( );
reverse_iterator<RandomIterator> operator--( int );
傳回值
第一個運算子會傳回 predecremented reverse_iterator 和第二個, postdecrement 運算子,傳回遞減的 reverse_iterator的複本。
備註
此成員函式,如果 reverse_iterator 滿足雙向 Iterator,的需求可能只能透過取得。
範例
// reverse_iterator_op_decr.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 first element
vector <int>::reverse_iterator rVPOS1 = vec.rend ( ) - 1;
cout << "The iterator rVPOS1 initially points to the last "
<< "element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
rVPOS1--; // postdecrement, predecrement: --rVPSO1
cout << "After the decrement, the iterator rVPOS1 points\n"
<< " to the next-to-last element in the reversed sequence: "
<< *rVPOS1 << "." << endl;
}
需求
標題: <iterator>
命名空間: std