Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // count_if example
- #include <iostream> // std::cout
- #include <algorithm> // std::count_if
- #include <vector> // std::vector
- bool IsOdd (int i) { return ((i%2)==1); }
- int main () {
- std::vector<int> myvector;
- for (int i=1; i<10; i++) myvector.push_back(i); // myvector: 1 2 3 4 5 6 7 8 9
- int mycount = count_if (myvector.begin(), myvector.end(), IsOdd);
- std::cout << "myvector contains " << mycount << " odd values.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement