C++ unordered_set clear() Function
Example
Remove all elements from an unordered set:
unordered_set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars.clear();
cout << cars.size();
Definition and Usage
The clear() function removes all elements from an unordered set. After clear(), the size of the unordered set is 0.
The clear function is defined in the <unordered_set> header file.
Tip: Use erase() to remove only some of the elements.
Syntax
unordered_set.clear()
Parameter Values
None.
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about unordered sets in our Unordered Set Tutorial.