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;
}
必要条件
ヘッダー: <スタック>
名前空間: std