list::rbegin
傳回迭代器,為反轉表中的第一個項目定址。
const_reverse_iterator rbegin( ) const;
reverse_iterator rbegin( );
傳回值
反向雙向 Iterator 解決已反轉清單的第一個項目 (或處理還沒有這個 unreversed 清單中的最後一個元素)。
備註
正使用 啟動 與清單,rbegin 搭配已還原的清單。
如果傳回值 rbegin 給 const_reverse_iterator,則無法修改清單物件。 如果傳回值 rbegin 給 reverse_iterator,則可以修改清單物件。
rbegin 可用來將清單向後逐一查看。
範例
// list_rbegin.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main( )
{
using namespace std;
list <int> c1;
list <int>::iterator c1_Iter;
list <int>::reverse_iterator c1_rIter;
// If the following line replaced the line above, *c1_rIter = 40;
// (below) would be an error
//list <int>::const_reverse_iterator c1_rIter;
c1.push_back( 10 );
c1.push_back( 20 );
c1.push_back( 30 );
c1_rIter = c1.rbegin( );
cout << "The last element in the list is " << *c1_rIter << "." << endl;
cout << "The list is:";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
// rbegin can be used to start an iteration through a list in
// reverse order
cout << "The reversed list is:";
for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
cout << " " << *c1_rIter;
cout << endl;
c1_rIter = c1.rbegin( );
*c1_rIter = 40;
cout << "The last element in the list is now " << *c1_rIter << "." << endl;
}
需求
標題: <list>
命名空間: std