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