C++ stack empty() Function
Example
Find out if a stack is empty or not:
stack<string> cars;
cout << cars.empty() << "\n";
cars.push("Volvo");
cout << cars.empty();
Definition and Usage
The empty() function checks whether a stack is empty or not.
It returns 1 (true) if the stack has no elements, and 0 (false) otherwise.
The empty function is defined in the <stack> header file.
Syntax
stack.empty();
Parameter Values
None.
Technical Details
| Returns: | A bool value: true (1) if the stack is empty, and false (0) if it is not. |
|---|
Related Pages
Read more about stacks in our Stacks Tutorial.