Share via


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 クラス

標準テンプレート ライブラリ