ฟังก์ชัน bitset::all() เป็นฟังก์ชันในตัว (inbuilt function) ของ C++ STL (Standard Template Library) ฟังก์ชันนี้คืนค่าบูลลีน (Boolean value) ค่าที่คืนจะเป็น true หากบิตทั้งหมดของ bitset ที่เรียกใช้เป็น 1 มิฉะนั้นจะคืนค่า false
ฟังก์ชันนี้ไม่รับพารามิเตอร์ใดๆ และคืนค่าบูลลีน
ไวยากรณ์
bool bitset_name.all()
ตัวอย่างข้อมูล
Bitset = 100101
ผลลัพธ์
false
เพราะบิตทั้งหมดของเซตต้องเป็น true (1) ถึงจะคืนค่า 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