Does std::stack expose iterators?

后端 未结 5 1250
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 08:57

Does the std::stack in the C++ STL expose any iterators of the underlying container or should I use that container directly?

5条回答
  •  甜味超标
    2020-11-29 09:27

    Stack does not have iterators, by definition of stack. If you need stack with iterators, you'll need to implement it yourself on top of other container (std::list, std::vector, etc). Stack doc is here.

    P.S. According to a comment i got from Iraimbilanja, std::stack by default uses std::deque for implementation.

提交回复
热议问题