无涯教程-C++ Bitset - none()函数

47 阅读1分钟

C++ bitsetnone()函数用于检查是否未设置任何位。如果未设置任何位,则返回true,否则返回false。

none - 语法

bool none();

none - 返回值

它返回布尔值true或false。

none - 例子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.

参考链接

www.learnfk.com/c++/cpp-bit…