Source of any_of1a.cpp


  1: //any_of1a.cpp

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

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates the use of the STL any_of() "
 11:         "algorithm from <algorithm>\nto determine whether any of "
 12:         "the values in a vector of integers is odd.";
 13:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');

 15:     int a[] = {2, 4, 6, 8, 10, 12, 14};
 16:     vector<int> v(begin(a), end(a));
 17:     cout << boolalpha;
 18:     cout << any_of(begin(v), end(v), [](int n){return n%2==1;}) << endl;
 19:     v.at(2) = 5;
 20:     cout << any_of(begin(v), end(v), [](int n){return n%2==1;}) << endl;
 21:     cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
 22: }