Source of find_if_not1a.cpp


  1: //find_if_not1a.cpp

  3: #include <iostream>
  4: #include <algorithm>
  5: #include <vector>
  6: #include <iterator>
  7: using namespace std;

  9: int main()
 10: {
 11:     cout << "\nThis program illustrates the use of the STL find_if_not() "
 12:         "algorithm from\n<algorithm> to find the first integer that "
 13:         "is not odd in a vector of integers.";
 14:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');

 16:     int a[] = {1, 3, 5, 7, 8, 9, 11};
 17:     vector<int> v(begin(a), end(a));
 18:     auto firstNotOdd =
 19:         find_if_not(begin(v), end(v), [](int n){return n%2==1;});
 20:     cout << "\nThe first integer that is not odd is "
 21:         << *firstNotOdd << ".\n";
 22:     cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
 23: }