A stack is a last-in, first-out (LIFO) data structure where elements can only be added or removed from one end of the structure, called the top. The std::stack class in C++ uses an underlying container like vector or deque to store elements. It provides functions like push() to add elements, pop() to remove elements, and top() to access the top element. Example code shows how to use a stack to store integers, display the size, insert and remove elements, and check the top element.