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



描述

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

宣告

以下是來自 <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("1110");

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

   b1 = b2;

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

   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

Both bitsets are not equal.
Both bitsets are equal.
bitset.htm
廣告
© . All rights reserved.