C++ unordered_map clear() Function
Example
Remove all elements from an unordered map:
unordered_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 an unordered map. After clear(), the size of the unordered map is 0.
The clear function is defined in the <unordered_map> header file.
Tip: Use erase() to remove only some of the elements.
Syntax
unordered_map.clear()
Parameter Values
None.
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about unordered maps in our Unordered Map Tutorial.