源码:
#include<iostream>#include<stack>using namespace std;//栈容器void test01() {//特点:先进后出stack<int>s;//入栈s.push(10);s.push(20);s.push(30);s.push(40);//只要栈不为空,查看栈顶,并执行出栈操作while (!s.empty()) {//查看栈顶元素cout << "栈顶元素为:" << s.top() << endl;//出栈s.pop();}cout << "栈的大小为:" << s.size() << endl;}int main() {test01();return 0;}
运行结果:
