I'm a beginner in c++. I was learning STL especially vectors & iterators uses..I was trying to use (find_if) function to display even numbers on the screen.I knew that I have to return boolean value to the third field in the function(find_if) ..but it gives me all elements in the vector !!! .but,When I used the function (GreaterThanThree) the code outputs the right values without any problem. this is my code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool EvenNumber(int i)
{
return i%2==0
}
/*bool GreaterThanThree(int s)
{
return s>3;
}
*/
int main()
{
vector <int> v={2,1,4,5,0,3,6,7,8,10,9};
sort(v.begin(),v.end());
auto it= find_if(v.begin(),v.end(),EvenNumber);
for(;it!=v.end();it++)
{
cout<<*it<<" ";
}
return 0;
}