bitset all() 函數是 C++ STL(標準模板庫)的內置函數。此函數返回一個布爾值。如果調用位集的所有位都為 1,則返回值為真,否則將返回假。
該函數不接受任何參數並返回一個布爾值。
用法
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
相關用法
- C++ Bitset any()用法及代碼示例
- C++ Bitset reference()用法及代碼示例
- C++ Bitset reset()用法及代碼示例
- C++ Bitset hash()用法及代碼示例
- C++ Bitset to_string()用法及代碼示例
- C++ Bitset bitset()用法及代碼示例
- C++ Bitset test()用法及代碼示例
- C++ Bitset to_ulong()用法及代碼示例
- C++ Bitset set()用法及代碼示例
- C++ Bitset none()用法及代碼示例
- C++ Bitset to_ullong()用法及代碼示例
- C++ Bitset flip()用法及代碼示例
- C++ Bitset count()用法及代碼示例
- C++ Boost.Lexical_Cast用法及代碼示例
- C++ unordered_map cbegin用法及代碼示例
- C++ map lower_bound()用法及代碼示例
- C++ Unordered_multimap reserve()用法及代碼示例
- C++ list assign()用法及代碼示例
- C++ std::max()用法及代碼示例
- C++ std::string::push_back()用法及代碼示例
注:本文由純淨天空篩選整理自Sudhir sharma大神的英文原創作品 Bitset all() function in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。