map::rend

返回解决成功最后一个元素所在的位置反转的映射的迭代器。

const_reverse_iterator rend( ) const; 
reverse_iterator rend( );

返回值

解决成功最后一个元素所在的位置反转的映射的反向双向迭代器(在前面unreversed映射的第一个元素)的位置。

备注

结束 用于映射,rend 用于取消的映射。

如果 rend 的返回值赋给 const_reverse_iterator,则不能修改映射对象。如果 rend 的返回值赋给 reverse_iterator,则可以修改映射对象。

rend 可用于测试对反向迭代器是否已到达其映射的末尾。

不应取消引用 rend 返回的值。

示例

// map_rend.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   map <int, int> m1;

   map <int, int> :: iterator m1_Iter;
   map <int, int> :: reverse_iterator m1_rIter;
   map <int, int> :: const_reverse_iterator m1_crIter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );

   m1_rIter = m1.rend( );
   m1_rIter--;
   cout << "The last element of the reversed map m1 is "
        << m1_rIter -> first << "." << endl;

   // begin can be used to start an iteration 
   // through a map in a forward order
   cout << "The map is: ";
   for ( m1_Iter = m1.begin( ) ; m1_Iter != m1.end( ); m1_Iter++)
      cout << m1_Iter -> first << " ";
      cout << "." << endl;

   // rbegin can be used to start an iteration 
   // through a map in a reverse order
   cout << "The reversed map is: ";
   for ( m1_rIter = m1.rbegin( ) ; m1_rIter != m1.rend( ); m1_rIter++)
      cout << m1_rIter -> first << " ";
      cout << "." << endl;

   // A map element can be erased by dereferencing to its key 
   m1_rIter = --m1.rend( );
   m1.erase ( m1_rIter -> first );

   m1_rIter = m1.rend( );
   m1_rIter--;
   cout << "After the erasure, the last element "
        << "in the reversed map is "
        << m1_rIter -> first << "." << endl;
}
  
  
  
  

要求

标头: <map>

命名空间: std

请参见

参考

map Class

标准模板库