C++ Standard Library C++ STL Library

C++ <bitset> - operator== Function



The C++ bitset::operator== function is used to check if two bitsets are equal or not. It returns true if two bitsets are equal, else returns false.

Syntax

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

Parameters

rhs Specify right-hand side bitset object.

Return Value

Returns true if two bitsets are equal, else returns false.

Exception

Never throws exceptions.

Example:

In the example below, the bitset::operator== function is used to check if two bitsets are equal or not.

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

  cout<<boolalpha;
  //checking if bitsets are equal or not
  cout<<"(bset1 == bset2): "<<(bset1 == bset2);
  cout<<endl;
  cout<<"(bset1 == bset3): "<<(bset1 == bset3);

  return 0;
}

The output of the above code will be:

(bset1 == bset2): true
(bset1 == bset3): false

❮ C++ <bitset> Library