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