list::rend

返回解决成功最后一个元素的位置在反向列表的迭代器。

const_reverse_iterator rend( ) const;
reverse_iterator rend( );

返回值

解决成功最后一个元素所在的位置反转的反向双向迭代器列表(位于在unreversed的第一个元素的位置列表)。

备注

结束 使用列表,rend 使用反向列表。

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

rend 可用于测试对反向迭代器是否已到达其的终点列表。

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

示例

// list_rend.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 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
   // list <int>::const_reverse_iterator c1_rIter;
   
   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1_rIter = c1.rend( );
   c1_rIter --;  // Decrementing a reverse iterator moves it forward in 
                 // the list (to point to the first element here)
   cout << "The first 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;

   // rend can be used to test if an iteration is through all of the 
   // elements of a reversed list
   cout << "The reversed list is:";
   for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
      cout << " " << *c1_rIter;
   cout << endl;

   c1_rIter = c1.rend( );
   c1_rIter--;  // Decrementing the reverse iterator moves it backward 
                // in the reversed list (to the last element here)

   *c1_rIter = 40;  // This modification of the last element would have 
                    // caused an error if a const_reverse iterator had 
                    // been declared (as noted above)

   cout << "The modified reversed list is:";
   for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
      cout << " " << *c1_rIter;
   cout << endl;
}
  

要求

标头: <list>

命名空间: std

请参见

参考

list Class

标准模板库