共用方式為


reverse_iterator::base

從其 reverse_iterator還原基礎的 Iterator。

RandomIterator base( ) const;

傳回值

基礎 reverse_iterator的 Iterator。

備註

與其基礎 Iterator 關聯性所有反向 Iterator 的識別為:

&* (reverse_iterator (i) ==) &* i (– 1)。

實際上,這表示此反向順序 reverse_iterator 會參考 (右側) Iterator 這些索引鍵參考此項目以外的項目的位置。 因此,如果 Iterator 解決了這個序列 (2, 4, 6, 8),然後 reverse_iterator 的元素 6 會說明這個反向順序 (8, 6, 4, 2) 的元素 4。

範例

// reverse_iterator_base.cpp
// compile with: /EHsc
#include <iterator>
#include <algorithm>
#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 );
   }
   
   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;

   vector <int>::iterator pos, bpos;
   pos = find ( vec.begin ( ), vec.end ( ), 6 );
   cout << "The iterator pos points to: " << *pos << "." << endl;

   typedef reverse_iterator<vector<int>::iterator>::iterator_type it_vec_int_type;

   reverse_iterator<it_vec_int_type> rpos ( pos );
   cout << "The reverse_iterator rpos points to: " << *rpos 
        << "." << endl;

   bpos = rpos.base ( );
   cout << "The iterator underlying rpos is bpos & it points to: " 
        << *bpos << "." << endl;
}

Output

The vector vec is: ( 2 4 6 8 10 ).
The vector vec reversed is: ( 10 8 6 4 2 ).
The iterator pos points to: 6.
The reverse_iterator rpos points to: 4.
The iterator underlying rpos is bpos & it points to: 6.

需求

標題: <iterator>

命名空間: std

請參閱

參考

reverse_iterator Class

標準樣板程式庫