Export (0) Print
Expand All

queue::queue

Constructs a queue that is empty or that is a copy of a base container object.

queue( ); 
explicit queue(
   const container_type& _Right
);

_Right

The const container of which the constructed queue is to be a copy.

The default base container for queue is deque. You can also specify list as a base container, but you cannot specify vector, because it lacks the required pop_front member function.

// queue_queue.cpp
// compile with: /EHsc
#include <queue>
#include <vector>
#include <list>
#include <iostream>

int main( )
{
   using namespace std;

   // Declares queue with default deque base container
   queue <char> q1;

   // Explicitly declares a queue with deque base container
   queue <char, deque<char> > q2;

   // These lines don't cause an error, even though they
   // declares a queue with a vector base container
   queue <int, vector<int> > q3;
   q3.push( 10 );
   // but the following would cause an error because vector has 
   // no pop_front member function
   // q3.pop( );

   // Declares a queue with list base container
   queue <int, list<int> > q4;
   
   // The second member function copies elements from a container
   list<int> li1;
   li1.push_back( 1 );
   li1.push_back( 2 );
   queue <int, list<int> > q5( li1 );
   cout << "The element at the front of queue q5 is "
        << q5.front( ) << "." << endl;
   cout << "The element at the back of queue q5 is "
        << q5.back( ) << "." << endl;
}
The element at the front of queue q5 is 1.
The element at the back of queue q5 is 2.

Header: <queue>

Namespace: std

Community Additions

ADD
Show:
© 2014 Microsoft