#include<stack>
#include<iostream>
using namespace std;
int main()
{
stack<int> a;
a.push(2);//将数字2压入栈中;
int b=a.top();//访问栈顶;
a.pop();//栈顶的元素出栈;
cout<<a.size()<<endl;//访问栈的大小
if(a.empty())
{
cout<<"为空栈"<<endl;//判断是否为空栈
}
#include<iostream>
using namespace std;
int main()
{
stack<int> a;
a.push(2);//将数字2压入栈中;
int b=a.top();//访问栈顶;
a.pop();//栈顶的元素出栈;
cout<<a.size()<<endl;//访问栈的大小
if(a.empty())
{
cout<<"为空栈"<<endl;//判断是否为空栈
}
}
栈的使用方法就5个函数,push,pop,top,empty,size。