c++ remove element from vector
vector.erase(position) // remove certain position
// or
vector.erase(left,right) // remove positions within range
c++ remove element from vector
vector.erase(position) // remove certain position
// or
vector.erase(left,right) // remove positions within range
remove element by value vector c++
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<int> v;
//Insert values 1 to 10
v.push_back(20);
v.push_back(10);
v.push_back(30);
v.push_back(20);
v.push_back(40);
v.push_back(20);
v.push_back(10);
vector<int>::iterator new_end;
new_end = remove(v.begin(), v.end(), 20);
for(int i=0;i<v.size(); i++){
cout << v[i] << " ";
}
//Prints [10 30 40 10]
return 0;
}
C++Copy
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us