📜  C++ STL-bitset.any()函数

📅  最后修改于: 2020-10-17 06:04:00             🧑  作者: Mango

C++ bitset any()函数

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

句法

bool any();

参数

它不带任何参数。

返回值

它返回布尔值0或1。

例子1

#include 
#include 
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"
<

输出:

1100 has a minimum of one-bit set
000000 does not have any bits set

例子2

#include 
#include 
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"
<

输出:

2 has a minimum of one-bit set
0 does not have any bits set