C++ bitsetnone()函数用于检查是否未设置任何位。如果未设置任何位,则返回true,否则返回false。
bool none();
它返回布尔值true或false。
#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.
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)