Export (0) Print
Expand All

queue::back

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

value_type& back( );
const value_type& 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.

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.

See Also

queue Class | queue Members | queue Functions Sample

Show:
© 2014 Microsoft