Export (0) Print
Expand All

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;

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

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.

// 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;
}

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

Header: <queue>

Namespace: std

Community Additions

ADD
Show:
© 2014 Microsoft