countif1.cpp

We use cookies. Read the Privacy and Cookie Policy

countif1.cpp

#include ‹stl.h›

#include ‹iostream.h›

int odd(int a_) {

 return a_ % 2;

}

int main() {

 vector‹int› numbers(100);

 for (int i = 0; i ‹ 100; i++) numbers[i] = i % 3;

 int elements = 0;

 count_if(numbers.begin(), numbers.end(), odd, elements);

 cout ‹‹ "Found " ‹‹ elements ‹‹ " odd elements." ‹‹ endl;

 return 0;

}