다음을 통해 공유


list::back 및 list::front

사용 하는 방법을 보여 줍니다 있는 list::backlist::front Visual C++에서 표준 템플릿 라이브러리 (STL) 함수입니다.

reference back( ); 
const_reference back( ) const; 
reference front( ); 
const_reference front( ) const; 
void pop_back( ); 
void pop_front( ); 
void push_back(
   const T& x
);
void push_front(
   const T& x
);

설명

[!참고]

프로토타입에 클래스/매개 변수 이름은 헤더 파일에서 버전이 일치 하지 않습니다.일부 가독성을 높이기 위해 수정 되었습니다.

다시 멤버 함수 제어 되는 시퀀스의 마지막 요소에 대 한 참조를 반환 합니다.front 멤버 함수는 제어 된 시퀀스의 첫 번째 요소에 대 한 참조를 반환 합니다.pop_back 멤버 함수는 제어 된 시퀀스의 마지막 요소를 제거 합니다.pop_front 멤버 함수는 제어 된 시퀀스의 첫 번째 요소를 제거 합니다.이러한 모든 함수가 제어 된 시퀀스 비어 있지 않은 있어야 합니다.Push_back 멤버 함수 값 가진 요소를 삽입 합니다. x 제어 되는 시퀀스의 끝에.Push_front 멤버 함수 값 가진 요소를 삽입 합니다. x 제어 되는 시퀀스의 시작 부분입니다.

예제

// liststck.cpp
// compile with: /EHsc
//  This example shows how to use the various stack
//                 like functions of list.
//
// Functions:
//    list::back
//    list::front
//    list::pop_back
//    list::pop_front
//    list::push_back
//    list::push_front

#pragma warning (disable:4786)
#include <list>
#include <string>
#include <iostream>

using namespace std ;

typedef list<string> LISTSTR;

int main()
{
    LISTSTR test;

    test.push_back("back");
    test.push_front("middle");
    test.push_front("front");

    // front
    cout << test.front() << endl;

    // back
    cout << test.back() << endl;

    test.pop_front();
    test.pop_back();

    // middle
    cout << test.front() << endl;
}

Output

front
back
middle

요구 사항

헤더: <list>

참고 항목

개념

표준 템플릿 라이브러리 샘플