是否可以在C中遍历std :: stack?
使用以下方法遍历不适用.因为std :: stack没有成员端.
- std::stack<int> foo;
- // ..
- for (__typeof(foo.begin()) it = foo.begin(); it != foo.end(); it++)
- {
- // ...
- }
解决方法
Is it possible to traverse std::stack in C++?
不是.堆栈是一种数据结构,当您有兴趣将元素放在顶部并从顶部获取元素时,您应该使用它.如果你想要一个可迭代的堆栈,要么为堆栈角色(std :: vector?)使用不同的数据结构,要么自己编写一个.