#include <stack>
using namespace std;
stack<元素类型[,底层容器类型]> 堆栈对象(构造实参表);
底层容器:vector/deque(默认)/list
push -> push_back
pop -> pop_back
top -> back
size -> size
empty -> empty
clear -> clear
#include <iostream> #include <stack> #include <vector> #include <list> using namespace std; int main (void) { // stack<string, vector<string> > ss; // stack<string, list<string> > ss; stack<string> ss; ss.push ("C++!"); ss.push ("喜欢"); ss.push ("我们"); while (! ss.empty ()) { cout << ss.top () << flush; ss.pop (); } cout << endl; return 0; }