list::back

返回对列表的最后一个元素。

reference back( ); 
const_reference back( ) const;

返回值

列表的最后一个元素。 如果列表为空,则返回值是不确定的。

备注

如果 back 的返回值赋给 const_reference,不能修改列表对象。 如果 back 的返回值赋给 reference,可以修改列表对象。

当编译_SECURE_SCL 1,则运行时将发生错误时,如果尝试访问该空一个元素列表。 有关更多信息,请参见经过检查的迭代器

示例

// list_back.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( ) 
{
   using namespace std;
   list <int> c1;
   
   c1.push_back( 10 );
   c1.push_back( 11 );

   int& i = c1.back( );
   const int& ii = c1.front( );

   cout << "The last integer of c1 is " << i << endl;
   i--;
   cout << "The next-to-last integer of c1 is " << ii << endl;
}
  

要求

标头: <list>

命名空间: std

请参见

参考

list Class

list::back 和 list::front

标准模板库