Cpp-standard-library-cpp-bitset-operator-equal-to

提供:Dev Guides
移動先:案内検索

C ++ビットセットライブラリ-operator ==関数

説明

C ++関数 *std
bitset :: operator ==* は、2つのビットセットが等しいかどうかをテストします。

宣言

以下は、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.