fork(1) download
  1. #include <iostream>
  2. #include<vector>
  3. #include <algorithm>
  4. #include <iterator>
  5.  
  6. int main() {
  7. std::vector< int > numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  8. auto is_odd = [](int x){ return x % 2; };
  9.  
  10. std::vector<int> odds;
  11. std::copy_if(numbers.begin(), numbers.end(), std::back_inserter(odds), is_odd);
  12.  
  13. for(auto a : odds)
  14. std::cout << a << ' ';
  15. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1 3 5 7 9