C++ map empty() Function
Example
Check if two maps are empty:
map<string, int> people = {{"John", 32}, {"Adele", 45}, {"Bo", 29}};
map<string, int> students;
cout << people.empty() << "\n";
cout << students.empty();
Definition and Usage
The empty() function checks whether a map is empty or not.
It returns 1 (true) if the map has no elements, and 0 (false) if it has one or more elements.
The empty function is defined in the <map> header file.
Syntax
map.empty()
Parameter Values
None.
Technical Details
| Returns: | A boolean value: true (1) if the map is empty, and false (0) if it is not. |
|---|
Related Pages
Read more about maps in our Maps Tutorial.