std::bitset<N>::operator==, std::bitset<N>::operator!=
來自 cppreference.com
bool operator==( const bitset& rhs ) const; |
(1) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
bool operator!=( const bitset& rhs ) const; |
(2) | (C++11 起無異常丟擲) (C++20 前) |
1) 如果 *this 和 rhs 的所有位都相等,則返回 true。
2) 如果 *this 和 rhs 中的任何位不相等,則返回 true。
|
(C++20 起) |
[編輯] 引數
rhs | - | 要比較的 bitset |
[編輯] 返回值
1) 如果 *this 中每個位的值都等於 rhs 中相應位的值,則為 true,否則為 false。
2) 如果 !(*this == rhs),則為 true,否則為 false。
[編輯] 示例
比較給定的 bitset 以確定它們是否相同
執行此程式碼
#include <bitset> #include <iostream> int main() { std::bitset<4> b1(0b0011); std::bitset<4> b2(b1); std::bitset<4> b3(0b0100); std::cout << std::boolalpha; std::cout << "b1 == b2: " << (b1 == b2) << '\n'; std::cout << "b1 == b3: " << (b1 == b3) << '\n'; std::cout << "b1 != b3: " << (b1 != b3) << '\n'; // b1 == std::bitset<3>{}; // compile-time error: incompatible types }
輸出
b1 == b2: true b1 == b3: false b1 != b3: true