다음을 통해 공유


list::begin

목록에서 첫 번째 요소의 주소를 지정 하는 반복기를 반환 합니다.

const_iterator begin( ) const;
iterator begin( );

반환 값

주소 목록에서 또는 이후 빈 목록 위치에 첫 번째 요소는 양방향 반복기입니다.

설명

경우 반환 값의 시작 배정은 const_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

표준 템플릿 라이브러리