1 #include<iostream> 2 #include<stack> 3 4 using namespace std; 5 6 void test01() 7 { 8 stack<int> s1; 9 s1.push(10); 10 s1.push(20); 11 s1.push(30); 12 s1.push(100); 13 // 栈中 14 // ||------------- 15 // || 10 20 30 100 16 // ||------------- 17 cout << "s1.top() = " << s1.top() << endl; 18 stack<int> s2(s1); 19 s2.pop();//弹出100 先进后出; 20 // 栈中 21 // ||---------- 22 // || 10 20 30 23 // ||---------- 24 while (!s2.empty()) 25 { 26 cout << s2.top() << " "; 27 s2.pop(); 28 } 29 } 30 31 int main() 32 { 33 test01(); 34 return 1; 35 }
s1.top() = 100
30 20 10