#include <algorithm>
#include <vector>
// using the erase-remove idiom
std::vector<int> vec {2, 4, 6, 8};
int value = 8 // value to be removed
vec.erase(std::remove(vec.begin(), vec.end(), value), vec.end());
std::vector<int> v;
// fill it up somehow
v.erase(std::remove(v.begin(), v.end(), 99), v.end());
// really remove all elements with value 99
#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
//C++20 std::erase function wraps erase-remove idiom
std::vector<int> ivec{ 1, 5, 7, 2, 1, 3, 1, 7, 1 };
auto n = erase(ivec, 1); //ADL
std::cout << n << " elements erased
";
for (auto i : ivec)
std::cout << i << ' ';
}
#include <algorithm>
...
vec.erase(std::remove(vec.begin(), vec.end(), 8), vec.end());
remove(v.begin(),v.end(),val)
carVec.erase(std::remove_if(carVec.begin(), carVec.end(), [&id_to_delete](const Car& ele)->bool
{
return ele.getnewId() == id_to_delete;
}), carVec.end());