c++ 判断数组元素是否都是奇数(all_of)

时间:2025-02-24 12:07:32
#include <iostream>     // std::cout
#include <algorithm> // std::all_of
#include <array> // std::array
using namespace std;
int main () {
array<int,8> foo = {3,4,7,11,13,17,19,23}; if ( all_of(foo.begin(), foo.end(), [](int i){return i%2;}) )
cout << "All the elements are odd numbers.\n";
else{
cout<<"not all are odd\n";
}
return 0;
}