다음을 통해 공유


list::front

목록의 첫 번째 요소에 대한 참조를 반환합니다.

reference front( );  const_reference front( ) const;

반환 값

목록이 비어 있으면 반환이 정의되지 않습니다.

설명

front의 반환 값이 const_reference에 할당된 경우 목록 개체는 수정할 수 없습니다. front의 반환 값이 reference에 할당된 경우 목록 개체는 수정할 수 있습니다.

_SECURE_SCL 1로 컴파일할 때 빈 목록의 요소에 액세스하려고 하면 런타임 오류가 발생합니다. 자세한 내용은 Checked Iterators를 참조하십시오.

예제

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

int main() {
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );

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

   cout << "The first integer of c1 is " << i << endl;
   i++;
   cout << "The first integer of c1 is " << ii << endl;
}
  

요구 사항

헤더: <list>

네임스페이스: std

참고 항목

참조

list 클래스

list::back 및 list::front

표준 템플릿 라이브러리