AlgoMaster Logo

std::stack

Last Updated: May 17, 2026

10 min read

std::stack<T> is a last-in, first-out (LIFO) container adapter from the standard library. It isn't a new container in its own right; it's a thin wrapper around another container (a std::deque by default) that exposes only the operations a stack needs. This chapter covers what std::stack is, the small API it offers, why some of its methods look the way they do, how to swap out the underlying container, and the pitfalls that bite people who treat it like a std::vector.

Premium Content

Subscribe to unlock full access to this content and more premium articles.