C++ list remove() Function
Example
Remove all elements with the value BMW:
list<string> cars = {"Volvo", "BMW", "Ford", "BMW", "Mazda"};
cars.remove("BMW");
for (string car : cars) {
cout << car << "\n";
}
Definition and Usage
The remove() function removes all the elements that are equal to a specified value.
If no element has the value, the list does not change.
The remove function is defined in the <list> header file.
Syntax
list.remove(<type> value);
<type> refers to the type of the data that the list contains.
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The value of the elements to remove. |
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about lists in our List Tutorial.