首页 > 解决方案 > 试图找出向量中的任何元素是否为假

问题描述

只要元素仍然为假,我就需要遍历向量。我试图使用 any_of 检查是否有任何元素为假,但我一直在终端中收到错误。错误是“预期的表达式”。我的陈述有什么问题?

vector <bool> check(solarSystem.size(),false);
while(any_of(check.begin(), check.end(), [](bool k){return k == false;})

标签: c++loopswhile-loopbooleaniteration

解决方案


To get this out of unanswered questions queue... your code should work if you just add a closing parenthesis:

vector <bool> check(solarSystem.size(), false);
while (any_of(check.begin(), check.end(), [](bool x) { return !x; })) {
    // . . .
}

推荐阅读