How to remove all occurrences of specific value from array in C++

1 Answer

0 votes
#include <iostream>    
#include <algorithm>   

int main () {
  int arr[] = {1, 3, 2, 5, 2, 6, 2, 2, 2};     
  int *end = arr + sizeof(arr) / sizeof(int); 
  int value = 2;

  end = std::remove(arr, end, value);         
                                                 
  for (int *p = arr; p != end; p++)
    std::cout << *p << ' ';

  return 0;
}


/*
run:

1 3 5 6 

*/

 



answered Apr 13, 2020 by avibootz

Related questions

...