map::rbegin
傳回位址的 Iterator 以反轉對應的第一個項目。
const_reverse_iterator rbegin( ) const;
reverse_iterator rbegin( );
傳回值
解決反向雙向 Iterator 的解決一反轉對應的第一個項目或還沒有 unreversed 對應的最後一個項目。
備註
正使用 啟動 與對應,rbegin 以反轉對應。
如果傳回值 rbegin 給 const_reverse_iterator,則無法修改對應物件。 如果傳回值 rbegin 給 reverse_iterator,則可以修改對應物件。
rbegin 可用來將對應向後逐一查看。
範例
// map_rbegin.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.rbegin( );
cout << "The first 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.rbegin( );
m1.erase ( m1_rIter -> first );
m1_rIter = m1.rbegin( );
cout << "After the erasure, the first element "
<< "in the reversed map is "
<< m1_rIter -> first << "." << endl;
}
需求
標頭:<map>
命名空間: std