#include#include int main() { std::stack my_stack; my_stack.push(10); my_stack.push(20); my_stack.push(30); std::cout << "Top element is: " << my_stack.top() << std::endl; return 0; }
#includeIn this example, we create an empty stack of integers and use `std::stack::empty()` to check if it is empty. If it is empty, we print a message saying so. If it is not empty, we use `std::stack::top()` to inspect the top element (which we assume will not be reached in this case). Package library: Standard C++ Library (STL)#include int main() { std::stack my_stack; if (my_stack.empty()) { std::cout << "Stack is empty" << std::endl; } else { std::cout << "Top element is: " << my_stack.top() << std::endl; } return 0; }