C++ Bitset 中的 none()函数

首页 / C++入门教程 / C++ Bitset 中的 none()函数

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.

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

程序员进阶攻略 -〔胡峰〕

白话法律42讲 -〔周甲徳〕

10x程序员工作法 -〔郑晔〕

摄影入门课 -〔小麥〕

Vim 实用技巧必知必会 -〔吴咏炜〕

Spark核心原理与实战 -〔王磊〕

讲好故事 -〔涵柏〕

Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕

徐昊 · TDD项目实战70讲 -〔徐昊〕

好记忆不如烂笔头。留下您的足迹吧 :)