#include <iostream> #include <stack> //stack 不遍历 不支持随机访问 必须pop出去 才能进行访问 using namespace std; void test01() { //初始化 stack<int> s1; stack<int> s2(s1); //stack操作 //首先是压栈 s1.push(10); s1.push(20); s1.push(30); //返回栈顶元素 cout << "栈顶元素为 " << s1.top() << endl; //出栈 s1.pop(); //打印 不能遍历 cout top后只能pop掉 打印下一个元素 while (!s1.empty()) { cout << s1.top() << endl; s1.pop(); } //size() cout <<"size: "<< s1.size() << endl; //栈容器存放对象指针 自练 //栈容器存放对象 } int main() { }