C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ any()

C++ any()函数

C++ any()函数用于测试是否设置了 中的至少一位。它返回一个布尔值,即true或false。

语法

bool any(); 

参数

不带任何参数。

返回值

它返回一个布尔值0或1、

示例1

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
 // initialization
bitset<4> b1(string("1100"));
bitset<6> b2(string("000000"));
// function to check if any of
 // its bits are set or not
bool result1 = b1.any();
if (result1)
cout<< b1 << " has a minimum of one-bit set"
<<endl;
else
cout<< b1 << " does not have any bits set"
<<endl;
// function to check if any of
// its bits are set or not
bool result2 = b2.any();
if (result2)
cout<< b2 << "  has a minimum of one-bit set"
<<endl;
else
cout<< b2 << " does not have any bits set"
<<endl;
return 0;
} 
输出:
1100 has a minimum of one-bit set
000000 does not have any bits set 

示例2

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<4> b1(string("1100"));
bitset<4> b2(string("00"));
bool result1 = b1.any();
if (result1)
cout<< b1.count() << " has a minimum of one-bit set"
<<endl;
else
cout<< b1.count() << " does not have any bits set"
<<endl;
bool result2 = b2.any();
if (result2)
cout<< b2.count() << " has a minimum of one-bit set"
<<endl;
else
cout<< b2.count() << " does not have any bits set"
<<endl;
return 0;
} 
输出:
2 has a minimum of one-bit set
0 does not have any bits set 
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4