加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 检查数组中的所有布尔值是否为真?

发布时间:2020-12-16 10:44:03 所属栏目:百科 来源:网络整理
导读:参见英文答案 check if value exists in all indexes of array????????????????????????????????????4个 假设我有这个布尔数组: bool something[4] = {false,false,false}; 现在,有没有简单的方法来检查此数组中的所有值是否同时为true / false? 而不是像
参见英文答案 > check if value exists in all indexes of array????????????????????????????????????4个
假设我有这个布尔数组:

bool something[4] = {false,false,false};

现在,有没有简单的方法来检查此数组中的所有值是否同时为true / false?

而不是像这样做:

if(something[0] == false && something[1] == false..)
dothis();

解决方法

使用 std::all_of

if (std::all_of(std::begin(something),std::end(something),[](bool i)
            { 
              return i; // or return !i ;
            })) {
        std::cout << "All numbers are truen";
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读