Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ remove all elements equal to

#include <iostream>
#include <vector> 
#include <algorithm> 
using namespace std;

int main()
{
  // initalize a vector nums 
  vector<int> nums = {0,0,1,1,1,1,2,3,3};
  // this removes all instances of the value of nums[2] (1) 
  nums.erase(std::remove(nums.begin(), nums.end(), nums[2]), nums.end());
  
  // output: You will see there are no 1s in the list 
  for(auto i : nums)
    cout << i << ' ';
  cout << endl;
}
 
PREVIOUS NEXT
Tagged: #remove #elements #equal
ADD COMMENT
Topic
Name
8+1 =