共用方式為


queue::back

Returns a reference to the last and most recently added element at the back of the queue.

reference back( );
const_reference back( ) const;

Return Value

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

Remarks

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

When compiling with _SECURE_SCL 1, a runtime error will occur if you attempt to access an element in an empty queue. See Checked Iterators for more information.

Example

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

int main( ) 
{
   using namespace std;
   queue <int> q1;
   
   q1.push( 10 );
   q1.push( 11 );

   int& i = q1.back( );
   const int& ii = q1.front( );

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

Output

The integer at the back of queue q1 is 11.
The integer at the front of queue q1 is 10.

Requirements

Header: <queue>

Namespace: std

See Also

Concepts

queue Class

queue Members

queue Functions

Standard Template Library