You can access the topmost element (the one pushed the latest) of a stack container by using the member function top():
#include #include #include using namespace std;void main() { stack strstack; strstack.push("Bjarne"); strstack.push("Stroustrup"); string topmost = strstack.top(); // topmost element is "Stroustrup" cout<< "topmost element is: "<< topmost << endl;}