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 }

 

posted @ 2016-01-06 11:04  wswang  阅读(273)  评论(0编辑  收藏  举报