C++ 位集庫 - operator| 函式



描述

C++ 函式std::bitset::operator| 對bitset執行按位或運算。

宣告

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

C++98

template<size_t N>
bitset<N> operator| (const bitset<N>& first, const bitset<N>& second);

C++11

template<size_t N>
bitset<N> operator| (const bitset<N>& first, const bitset<N>& second) noexcept;

引數

  • first − 第一個bitset物件。

  • second − 第二個bitset物件。

返回值

返回包含按位或運算結果的bitset。

異常

此成員函式從不丟擲異常。

示例

以下示例演示了std::bitset::operator| 函式的使用。

#include <iostream>
#include <bitset>

using namespace std;

int main(void) {

   bitset<4> b("1010");
   bitset<4> mask("0101");

   /* Turn on all bits */
   auto result = b | mask;

   cout << result << endl;

   return 0;
}

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

1111
bitset.htm
廣告