stack::top() function in C++ STL

In C++, the standard library gives us the facility to use the Stacks as a type of container adaptors with LIFO type of working. The stack::top() is a C++ Standard Library function which is used to get the top element of the stack.

Syntax: );

Parameter: The stack::top() function does not accepts any parameter.

Return value: The stack::top() function returns the current top element of the stack container.

Example of stack::top() Function

#include <iostream> 
#include <stack> 
using namespace std; 
int main() 
    stack<int> STK;
    while (!STK.empty()) 
        cout << << ' '; 


30 20 10 

This article is written by

Pratik Singhal

Pratik Singhal

Please comment below, if you have any doubts or find any error in the above article.

Leave a Reply

Your email address will not be published. Required fields are marked *

[gravityforms id="5" description="false" titla="false" ajax="true"]