list::begin

返回解决的迭代器列表中的第一个元素。

const_iterator begin( ) const;
iterator begin( );

返回值

解析一双向的迭代器第一个元素列表或给成功空位置列表中。

备注

如果 begin 的返回值赋给 const_iterator,不能修改在列表对象的元素。如果 begin 的返回值赋给 iterator,可以修改在列表对象的元素。

示例

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

int main( ) 
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;
   list <int>::const_iterator c1_cIter;
   
   c1.push_back( 1 );
   c1.push_back( 2 );

   c1_Iter = c1.begin( );
   cout << "The first element of c1 is " << *c1_Iter << endl;

   *c1_Iter = 20;
   c1_Iter = c1.begin( );
   cout << "The first element of c1 is now " << *c1_Iter << endl;

   // The following line would be an error because iterator is const
   // *c1_cIter = 200;
}
  

要求

标头: <list>

命名空间: std

请参见

参考

list Class

标准模板库