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