C++ 位集庫 - operator== 函式



描述

C++ 函式std::bitset::operator== 用於測試兩個位集是否相等。

宣告

以下是來自 std::bitset 標頭檔案的 std::bitset::operator== 函式的宣告。

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.
bitset.htm
廣告

© . All rights reserved.