C++ 位集库 - 运算符 == 函数


描述

C++ 函数std::bitset::operator==测试两个位集是否相等。

宣言

以下是 std::bitset::operator== 函数形式 std::bitset 标头的声明。

C++98

bool operator== (const bitset& other) const;

C++11

bool operator== (const bitset& other) const noexcept;

参数

other - 另一个位集对象。

返回值

如果两个位集相等则返回 true,否则返回 false。

例外情况

该成员函数从不抛出异常。

例子

以下示例显示了 std::bitset::operator== 函数的用法。

#include <iostream>
#include <bitset>

using namespace std;

int main(void) {
   bitset<4> b1("1010");
   bitset<4> b2("1010");

   if (b1 == b2)
      cout << "Both bitsets are equal." << endl;
   b1 >>= 1;

   if (!(b1 == b2))
      cout << "Both bitsets are not equal." << endl;

   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

Both bitsets are equal.
Both bitsets are not equal.
位集.htm