top

C/C++ Reference

top
Syntax:
  #include <stack>
  TYPE& top();

The function top() returns a reference to the top element of the stack.

For example, the following code removes all of the elements from a stack and uses top() to display them:

   while( !s.empty() ) {
     cout << s.top() << " ";
     s.pop();
   }            
Related topics: