repl.it
@talha131/

C++: Iterate Over An Array And Remove Elements

C++

https://www.oncrashreboot.com/iterate-over-an-array-and-remove-elements

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  std::vector<int> eg = {0,  1,  1,  2,  3,   5,   8,   13,
                        21, 34, 55, 89, 144, 233, 377, 610};

  eg.erase(
    std::remove_if(
                  eg.begin(), 
                  eg.end(),
                  [](int x) { 
                      return x > 99; 
                    }),
                  eg.end());
  // Print result
  std::for_each(eg.begin(), 
                eg.end(),
                [](const int &e) { 
                      std::cout << e << " "; 
                  });
}