【发布时间】:2014-06-05 08:23:23
【问题描述】:
是否可以在 C++ 中遍历std::stack?
使用以下方法遍历不适用。因为std::stack 没有成员end。
std::stack<int> foo;
// ..
for (__typeof(foo.begin()) it = foo.begin(); it != foo.end(); it++)
{
// ...
}
【问题讨论】:
-
这就是为什么它是一个“堆栈”。后进先出,就是这样(理论上)。
-
您选择了错误的数据类型。如果您希望能够对其进行迭代,请不要使用堆栈。