C ++ STL中的bitset all()函数
位all()方法是C++STL(标准模板库)的内置功能。该函数返回一个布尔值。如果调用位集中的所有位均为1,则返回值为true,否则它将返回false。
该函数不接受任何参数,并返回一个布尔值。
语法
Bool bitset_name .all()
示例
Bitset = 100101
输出结果
false
因为集合的所有位都必须为真才能返回真值。
示例
#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
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿