c++ 判断数组元素是否有负数(any_of)

 

#include <iostream>     // std::cout
#include <algorithm>    // std::any_of
#include <array>        // std::array
using namespace std;
int main () {
    array<int,7> foo = {0,1,-1,3,-3,5,-5};
    
    if ( any_of(foo.begin(), foo.end(), [](int i){return i<0;}) )
        cout << "There are negative elements in the range.\n";
    
    return 0;
}

 

posted @ 2018-10-19 10:30  anobscureretreat  阅读(1013)  评论(0编辑  收藏  举报