queue::front
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

queue::front

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

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

Example

// 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.

See Also

queue Class | queue Members | queue Functions Sample

Show:
© 2016 Microsoft