다음을 통해 공유


queue::front

Returns a reference to the first element at the front of the queue.

reference front( );
const_reference front( ) const;

반환 값

The first element of the queue. If the queue is empty, the return value is undefined.

설명

If the return value of front is assigned to a const_reference, the queue object cannot be modified. If the return value of front is assigned to a reference, the queue object can be modified.

The member function returns a reference to the first element of the controlled sequence, which must be nonempty.

When compiling with _SECURE_SCL 1, a runtime error will occur if you attempt to access an element in an empty queue. 자세한 내용은 Checked Iterators를 참조하십시오.

예제

// queue_front.cpp
// compile with: /EHsc
#include <queue>
#include <iostream>

int main() {
   using namespace std;
   queue <int> q1;

   q1.push( 10 );
   q1.push( 20 );
   q1.push( 30 );

   queue <int>::size_type i;
   i = q1.size( );
   cout << "The queue length is " << i << "." << endl;

   int& ii = q1.back( );
   int& iii = q1.front( );

   cout << "The integer at the back of queue q1 is " << ii 
        << "." << endl;
   cout << "The integer at the front of queue q1 is " << iii 
        << "." << endl;
}

Output

The queue length is 3.
The integer at the back of queue q1 is 30.
The integer at the front of queue q1 is 10.

요구 사항

Header: <queue>

네임스페이스: std

참고 항목

참조

queue 클래스

queue 함수

표준 템플릿 라이브러리