remove function in c++ vector code example
Example 1: remove element by index from vector c++
vec.erase(vec.begin() + 1);
vec.erase(vec.begin() + 1, vec.begin() + 3);
Example 2: 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 3: c++ remove element from vector
vector.erase(position)
vector.erase(left,right)
Example 4: remove element from vector on condition c++
v.erase(std::remove_if(
v.begin(), v.end(),
[](const int& x) {
return x > 10;
}), v.end());