C++ STL之stack
因为总用vector,却忘记了有stack,今天用到栈顶的值才想起来,说起来stack很方便,也很容易用,看下边例子:
1 #include<stack> 2 #include<iostream> 3 using namesapce std; 4 5 int main(void) 6 { 7 stack<int> v; 8 v.push(0); 9 v.push(1); 10 cout<<v.size()<<endl; 11 cout<<v.top()<<endl; 12 cout<<v.empty()<<endl; 13 v.pop(); 14 cout<<v.top()<<endl; 15 16 }