C++ set empty() Function
Example
Check if two sets are empty:
set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
set<string> colors;
cout << cars.empty() << "\n";
cout << colors.empty();
Definition and Usage
The empty() function checks whether a set is empty or not.
It returns 1 (true) if the set has no elements, and 0 (false) if it has one or more elements.
The empty function is defined in the <set> header file.
Syntax
set.empty()
Parameter Values
None.
Technical Details
| Returns: | A boolean value: true (1) if the set is empty, and false (0) if it is not. |
|---|
Related Pages
Read more about sets in our Sets Tutorial.