fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include<algorithm>
  4. #include<iterator>
  5.  
  6. int main ()
  7. {
  8. std::vector<int> myvector {100, 145, 675, 0, 250, 43, 19};
  9.  
  10. std::size_t min =100, max=300;
  11.  
  12. std::cout<<"In Range "<<"[ "<<min<<", "<<max<<" ]"<<std::endl;
  13.  
  14. std::copy_if(myvector.begin(), myvector.end(), std::ostream_iterator<int>(std::cout," "),
  15. [=](const int& x)
  16. {
  17. return (x>=min) && (x<=max );
  18. }
  19. );
  20.  
  21. std::cout<<"\nAre [0,50,100]"<<std::endl;
  22. std::size_t a=0,b=50,c=100;
  23. std::copy_if(myvector.begin(), myvector.end(), std::ostream_iterator<int>(std::cout," "),
  24. [=](const int& x)
  25. {
  26. return (x==a) || (x == b ) || (x==c);
  27. }
  28. );
  29. std::size_t num=50;
  30. std::cout<<"\nAre multiple of"<<num<<std::endl;
  31. std::copy_if(myvector.begin(), myvector.end(), std::ostream_iterator<int>(std::cout," "),
  32. [=](const int& x)
  33. {
  34. return (x%num==0);
  35. }
  36. );
  37.  
  38. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
In Range [ 100, 300 ]
100 145 250 
Are [0,50,100]
100 0 
Are multiple of50
100 0 250