queue::queue

构造为 NULL 或为基容器对象的副本的队列。

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

参数

  • _Right
    构造的队列是容器复制的 const

备注

队列的默认基容器是 deque。 还可以指定列表作为基本,容器,但不能指定矢量,因为缺少必需的 pop_front 成员函数。

示例

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

要求

页眉: <队列>

命名空间: std

请参见

参考

queue 类

标准模板库