Advertisement
frasl

Untitled

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