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