Note that pop() removes the next element but does not return it, whereas top() returns the next
element without removing it. Thus, you must always call both functions to process and remove the
next element from the stack. This interface is somewhat inconvenient, but it performs better if you
want only to remove the next element without processing it. Note that the behavior of top() and
pop() is undefined if the stack contains no elements. The member functions size() and empty()
are provided to check whether the stack contains elements.
If you don’t like the standard interface of stack, you can easily write a more convenient
interface. See Section 12.1.3, page 635, for an example.