次の方法で共有


reverse_iterator::operator->

reverse_iteratorによってアドレス要素へのポインターを返します。

pointer operator->( ) const;

戻り値

要素で reverse_iteratorアドレスへのポインター。

解説

演算子は &**thisを返します。

使用例

// reverse_iterator_ptrto.cpp
// compile with: /EHsc
#include <iterator>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>

int main( )
{
   using namespace std;

   typedef vector<pair<int,int> > pVector;
   pVector vec;
   vec.push_back(pVector::value_type(1,2));
   vec.push_back(pVector::value_type(3,4));
   vec.push_back(pVector::value_type(5,6));
   
   pVector::iterator pvIter;
   cout << "The vector vec of integer pairs is:\n( ";
   for ( pvIter = vec.begin ( ) ; pvIter != vec.end ( ); pvIter++)
      cout << "( " << pvIter -> first << ", " << pvIter -> second << ") ";
   cout << ")" << endl << endl;

   pVector::reverse_iterator rpvIter;
   cout << "The vector vec reversed is:\n( ";
   for ( rpvIter = vec.rbegin( ) ; rpvIter != vec.rend( ); rpvIter++ )
      cout << "( " << rpvIter -> first << ", " << rpvIter -> second << ") ";
   cout << ")" << endl << endl;

   pVector::iterator pos = vec.begin ( );
   pos++;
   cout << "The iterator pos points to:\n( " << pos -> first << ", " 
   << pos -> second << " )" << endl << endl;

   pVector::reverse_iterator rpos (pos); 

   // Use operator -> with return type: why type int and not int*?
   int fint = rpos -> first;
   int sint = rpos -> second;
   
   cout << "The reverse_iterator rpos points to:\n( " << fint << ", " 
   << sint << " )" << endl;
}
  

必要条件

ヘッダー: <iterator>

名前空間: std

参照

関連項目

reverse_iterator Class

標準テンプレート ライブラリ