1// Deletes the second element (vec[1])
2vec.erase(vec.begin() + 1);
3
4// Deletes the second through third elements (vec[1], vec[2])
5vec.erase(vec.begin() + 1, vec.begin() + 3);
1#include <algorithm>
2#include <vector>
3
4// using the erase-remove idiom
5
6std::vector<int> vec {2, 4, 6, 8};
7int value = 8 // value to be removed
8vec.erase(std::remove(vec.begin(), vec.end(), value), vec.end());
1// Deleting first element
2vector_name.erase(vector_name.begin());
3
4// Deleting xth element from start
5vector_name.erase(vector_name.begin()+(x-1));
6
7// Deleting from the last
8vector_name.pop_back();
1vector.erase(position) // remove certain position
2// or
3vector.erase(left,right) // remove positions within range
4
1
2
3// erase element from vector by its index
4 vector<string> strs {"first", "second", "third", "last"};
5
6 string element = "third"; // the element which will be erased
7 for(int i=0;i<strs.size();i++)
8 {
9 if(strs[i] == element)
10 strs.erase(strs.begin()+i);
11 }
12
13