bitset::none()是C++中的内置 STL,如果未设置任何位,则返回True。如果至少设置了一位,则返回False。
用法:
bool count()
参数:该函数不接受任何参数。
返回值:该函数返回一个布尔值。如果未设置任何布尔值,则为True。如果至少设置了一位,则为False。
下面的程序演示了bitset::none()函数。
示例1:
// CPP program to illustrate the
// bitset::none() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// initialization of bitset
bitset<4> b1(string("1100"));
bitset<6> b2(string("000000"));
// Function to check if none of
// the bits are set or not in b1
bool result1 = b1.none();
if (result1)
cout << b1 << " has no bits set"
<< endl;
else
cout << b1 << " has a minimum of one bit set"
<< endl;
// Function to check if none of
// the bits are set or not in b1
bool result2 = b2.none();
if (result2)
cout << b2 << " has no bits set"
<< endl;
else
cout << b2 << " has a minimum of one bit set"
<< endl;
return 0;
}
输出:
1100 has a minimum of one bit set 000000 has no bits set
示例2:
// CPP program to illustrate the
// bitset::none() function
// when the input is a number
#include <bits/stdc++.h>
using namespace std;
int main()
{
// initialization of bitset
bitset<3> b1(4);
bitset<6> b2(0);
// Function to check if none of
// the bits are set or not in b1
bool result1 = b1.none();
if (result1)
cout << b1 << " has no bits set"
<< endl;
else
cout << b1 << " has a minimum of one bit set"
<< endl;
// Function to check if none of
// the bits are set or not in b1
bool result2 = b2.none();
if (result2)
cout << b2 << " has no bits set"
<< endl;
else
cout << b2 << " has a minimum of one bit set"
<< endl;
return 0;
}
输出:
100 has a minimum of one bit set 000000 has no bits set
相关用法
- C++ bitset any()用法及代码示例
- C++ bitset all()用法及代码示例
- C++ bitset set()用法及代码示例
- C++ bitset operator[]用法及代码示例
- C++ bitset test()用法及代码示例
- C++ bitset count()用法及代码示例
- C++ bitset size()用法及代码示例
- C++ bitset::flip()用法及代码示例
- C++ bitset reset()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 bitset none() in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。