top

Syntax:

    #include <stack>
    TYPE& top();
    const TYPE& top() const;

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: pop