C++ Standard Library C++ STL Library

C++ <bitset> - operator|= Function



The C++ bitset::operator|= function is used to perform bitwise OR operation on the current bitset using the specified bitset.

Syntax

bitset& operator|= (const bitset& rhs);
bitset& operator|= (const bitset& rhs) noexcept;

Parameters

rhs Specify right-hand side bitset object.

Return Value

*this

Exception

Never throws exceptions.

Example:

In the example below, the bitset::operator|= function is used to perform bitwise OR operation on the given bitset.

#include <iostream>
#include <bitset>
using namespace std;
 
int main (){
  bitset<4> bset1("1001");
  bitset<4> bset2("1100");

  cout<<"bset1 is: "<<bset1;

  //performing bitwise OR operation on
  //bset1 using bset2
  bset1 |= bset2;

  cout<<"\nbset1 is: "<<bset1;

  return 0;
}

The output of the above code will be:

bset1 is: 1001
bset1 is: 1101

❮ C++ <bitset> Library