top [C++ Reference]
Keywords: stl,stack,top
Date: 2008-10-14T15:42:10-0700

[[top]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

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

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •