stack在BCB中是一个模板,在头文件<stack>中。具体的参数如下:
template <class T, class Container = deque<T> >
class stack;
T---表示是你要压栈的数据类型。
容器你可以自己实现,也可以使用默认的系统给你的容器。
#include <stack>
#include <vector>
#include <deque>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
// Make a stack using a vector container
stack<int,vector<int> > s;
// Push a couple of values on the stack
s.push(1);
s.push(2);
cout << s.top() << endl;
// Now pop them off
s.pop();
cout << s.top() << endl;
s.pop();
// Make a stack of strings using a deque
stack<string,deque<string> > ss;
// Push a bunch of strings on then pop them off
int i;
for (i = 0; i < 10; i++)
{
ss.push(string(i+1,'a'));
cout << ss.top() << endl;
}
for (i = 0; i < 10; i++)
{
cout << ss.top() << endl;
ss.pop();
}
return 0;
}
是帮助文件的一个例子,你可以自己去看一看。