fork download
  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. int arraylen = 4;
  7. int myArray[4] = { 1, 2, 3, 4 };
  8. for (int i =0; i < arraylen; ++i)
  9. std::cout << myArray[i] << ' ';
  10. std::cout << '\n';
  11.  
  12. //http://e...content-available-to-author-only...e.com/w/cpp/algorithm/remove
  13. arraylen = std::remove(myArray, myArray + arraylen, 2) - myArray;
  14.  
  15. for (int i =0; i < arraylen; ++i)
  16. std::cout << myArray[i] << ' ';
  17. std::cout << '\n';
  18. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1 2 3 4 
1 3 4