C++ STL 中的 bitset all() 函数
bitset all() 函数是 C++ STL(标准模板库) 的一个内置函数。此函数会返回一个布尔值。如果调用 bitset 的所有位都是 1,则会返回 true,否则将返回 false。
此函数不接受任何参数,并返回一个布尔值。
语法
Bool bitset_name .all()
示例
Bitset = 100101
输出
false
因为集合中的所有位都需要为 true 才能返回 true 值。
示例
#include <bits/stdc++.h>
using namespace std;
void printer(bool val){
if(val){
cout<< "The bitset has all bits set"<< endl;
} else{
cout << "The bitset does not have all bits set"<< endl;
}
}
int main() {
bitset<4> bit1(string("1011"));
bitset<6> bit2(string("111111"));
cout<<"The bitset is "<<bit1<<endl;
printer(bit1.all());
cout<<"The bitset is "<<bit2<<endl;
printer(bit2.all());
return 0;
}输出
The bitset is 1011 The bitset does not have all bits set The bitset is 111111 The bitset has all bits set
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP