Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
queue::back
Collapse the table of content
Expand the table of content

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;

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>

Community Additions

ADD
Show:
© 2015 Microsoft