C++ bitset none()函数
C++ bitsetnone()函数用于检查是否没有位被设置。如果没有位被设置,则返回true,否则返回false。
语法
bool none();
参数
它不接受任何参数。
返回值
它返回一个布尔值,可以是true或false。
示例1
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<16> foo;
bitset<4> b(string("1010"));
if (foo.none())
cout<< foo << " has no bits set.\n";
else
cout<< foo << " has " <<foo.count() << " bits set.\n";
if (b.none())
cout<< b << " has no bits set.\n";
else
cout<< b << " has " <<b.count() << " bits set.\n";
return 0;
}
输出:
0000000000000000 has no bits set.
1010 has 2 bits set.