c++ vector remove by value code example
Example 1: remove value from vector c++
#include <algorithm>
#include <vector>
std::vector<int> vec {2, 4, 6, 8};
int value = 8
vec.erase(std::remove(vec.begin(), vec.end(), value), vec.end());
Example 2: delete from front in vector c++
vector_name.erase(vector_name.begin());
vector_name.erase(vector_name.begin()+(x-1));
vector_name.pop_back();
Example 3: how to remove an element from a vector by value c++
std::vector<int> v;
v.erase(std::remove(v.begin(), v.end(), 99), v.end());