共用方式為


deque::rbegin

傳回 Iterator 以反轉雙向佇列中的第一個項目。

const_reverse_iterator rbegin( ) const; 
reverse_iterator rbegin( );

傳回值

解決反向隨機存取 Iterator 解決一反轉雙向佇列中的第一個項目或還沒有 unreversed 雙向佇列的最後一個項目。

備註

如同 啟動 使用雙向佇列,rbegin 以反轉雙向佇列。

如果傳回值 rbeginconst_reverse_iterator,無法修改雙向佇列物件。 如果傳回值 rbeginreverse_iterator,可以修改雙向佇列物件。

rbegin 可用來透過雙向佇列反向逐一查看。

範例

// deque_rbegin.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>

int main( ) 
{
   using namespace std;
   deque <int> c1;
   deque <int>::iterator c1_Iter;
   deque <int>::reverse_iterator c1_rIter;

   // If the following line had replaced the line above, an error 
   // would have resulted in the line modifying an element 
   // (commented below) because the iterator would have been const
   // deque <int>::const_reverse_iterator c1_rIter;
   
   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1_rIter = c1.rbegin( );
   cout << "Last element in the deque is " << *c1_rIter << "." << endl;

   cout << "The deque contains the elements: ";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << *c1_Iter << " ";
   cout << "in that order.";
   cout << endl;

   // rbegin can be used to iterate through a deque in reverse order
   cout << "The reversed deque is: ";
   for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
      cout << *c1_rIter << " ";
   cout << endl;

   c1_rIter = c1.rbegin( );
   *c1_rIter = 40;  // This would have caused an error if a 
                    // const_reverse iterator had been declared as 
                    // noted above
   cout << "Last element in deque is now " << *c1_rIter << "." << endl;
}
  

需求

標頭: <deque>

命名空間: std

請參閱

參考

deque 類別

deque::rbegin 和 deque::rend

標準樣板程式庫