stack::stack

构造为 NULL 或为基容器类的副本的堆栈。

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

参数

  • _Right
    构造的堆栈是复制的容器。

示例

// stack_stack.cpp
// compile with: /EHsc
#include <stack>
#include <vector>
#include <list>
#include <iostream>

int main( )
{
   using namespace std;

   // Declares stack with default deque base container
   stack <char> dsc1;

   //Explicitly declares a stack with deque base container
   stack <char, deque<char> > dsc2;

   // Declares a stack with vector base containers
   stack <int, vector<int> > vsi1;

   // Declares a stack with list base container
   stack <int, list<int> > lsi;
   
   // The second member function copies elements from a container
   vector<int> v1;
   v1.push_back( 1 );
   stack <int, vector<int> > vsi2( v1 );
   cout << "The element at the top of stack vsi2 is "
        << vsi2.top( ) << "." << endl;
}
  

要求

页眉: <堆栈>

命名空间: std

请参见

参考

stack 类

标准模板库