CppDS.com

C++ 98 11 14 17 20 手册

operator==,!=(std::bitset)

来自cppreference.com
< cpp‎ | utility‎ | bitset
 
 
工具库
通用工具
日期和时间
函数对象
格式化库 (C++20)
(C++11)
关系运算符 (C++20 中弃用)
整数比较函数
(C++20)
swap 与类型运算
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
常用词汇类型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等字符串转换
(C++17)
(C++17)
 
 
(1)
bool operator==( const bitset<N>& rhs ) const;
(C++11 前)
bool operator==( const bitset<N>& rhs ) const noexcept;
(C++11 起)
(2)
bool operator!=( const bitset<N>& rhs ) const;
(C++11 前)
bool operator!=( const bitset<N>& rhs ) const noexcept;
(C++11 起)
(C++20 前)
1)*thisrhs 中的所有位相等则返回 true 。
2)*thisrhs 中的任何位不相等则返回 true 。

参数

rhs - 要比较的 bitset

返回值

1)*this 中每位都等于 rhs 中对应位的值则为 true ,否则为 false
2)!(*this == rhs) 则为 true ,否则为 false

示例

比较二个 bitset 以确定它们是否等同:

#include <iostream>
#include <bitset>
 
int main()
{
    std::bitset<4> b1(3); // [0,0,1,1]
    std::bitset<4> b2(b1);
    std::bitset<4> b3(4); // [0,1,0,0]
 
    std::cout << "b1 == b2: " << (b1 == b2) << '\n';
    std::cout << "b1 == b3: " << (b1 == b3) << '\n';
    std::cout << "b1 != b3: " << (b1 != b3) << '\n';
}

输出:

b1 == b2: 1
b1 == b3: 0
b1 != b3: 1
关闭