C++ Bitset Library - operator^= Function


Advertisements


Description

The C++ function std::bitset::operator^= performs bitwise XOR operation on current bitset object.

Declaration

Following is the declaration for std::bitset::operator^= function form std::bitset header.

C++98

bitset& operator^= (const bitset& other);

C++11

bitset& operator^= (const bitset& other) noexcept;

Parameters

other − Another bitset object.

Return value

Returns this pointer.

Exceptions

This member function never throws exception.

Example

The following example shows the usage of std::bitset::operator^= function.

Live Demo
#include <iostream>
#include <bitset>

using namespace std;

int main(void) {
   bitset<4> b("1010");
   bitset<4> mask("1111");

   /* Invert each bit of bitset b */
   b ^= mask;

   cout << b << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

0101

bitset.htm

Advertisements