C++ map clear() Function
Example
Remove all elements from a map:
map<string, int> people = {{"John", 32}, {"Adele", 45}, {"Bo", 29}};
people.clear();
cout << people.size();
Definition and Usage
The clear() function removes all elements from a map. After clear(), the size of the map is 0.
The clear function is defined in the <map> header file.
Tip: Use erase() to remove only some of the elements.
Syntax
map.clear()
Parameter Values
None.
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about maps in our Maps Tutorial.