stack::pop

从堆栈的顶部移除元素。

void pop( );

备注

堆栈必须是非空应用成员函数。 堆栈顶部为最近添加的元素占据的该位置是最后一个元素在容器的末尾。

示例

// stack_pop.cpp
// compile with: /EHsc
#include <stack>
#include <iostream>

int main( )
{
   using namespace std;
   stack <int> s1, s2;

   s1.push( 10 );
   s1.push( 20 );
   s1.push( 30 );

   stack <int>::size_type i;
   i = s1.size( );
   cout << "The stack length is " << i << "." << endl;

   i = s1.top( );
   cout << "The element at the top of the stack is "
        << i << "." << endl;

   s1.pop( );

   i = s1.size( );
   cout << "After a pop, the stack length is " 
        << i << "." << endl;

   i = s1.top( );
   cout << "After a pop, the element at the top of the stack is "
        << i << "." << endl;
}
  
  
  
  

要求

标头: <stack>

命名空间: std

请参见

参考

stack Class

标准模板库