//me
vec.erase(vec.begin() + index); //index 0 means first element and so on
vector.erase(position) // remove certain position
// or
vector.erase(left,right) // remove positions within range
// erase element from vector by its index
vector<string> strs {"first", "second", "third", "last"};
string element = "third"; // the element which will be erased
for(int i=0;i<strs.size();i++)
{
if(strs[i] == element)
strs.erase(strs.begin()+i);
}
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> num{1, 2, 3, 4, 5};
// initial vector
cout << "Initial Vector: ";
for (int i : num) {
cout << i << " ";
}
// remove the last element
num.pop_back();
// final vector
cout << "
Updated Vector: ";
for (int i : num) {
cout << i << " ";
}
return 0;
}