#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());
// 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(){
//Creation of integer vector
vector<int> vectorArray ;
for(int i=1;i<10;i++){
vectorArray.push_back(i);
}
//vector elements are 1,2,3,4,5,6,7,8,9
vectorArray.pop_back();
for(int i=0;i<vectorArray.size();i++){
cout<<vectorArray[i]<<" ";
}
//vector elements are 1,2,3,4,5,6,7,8
cout<<endl;
vectorArray.clear();
// No elements are left in vector array
return 0;
}