bitset all() ทำหน้าที่ inbuilt ของ C++ STL( Standard Template Library) ฟังก์ชันนี้ส่งกลับค่าบูลีน ค่าที่ส่งคืนจะเป็นจริงหากบิตทั้งหมดของบิตเซ็ตที่เรียกเป็น 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