C++ Bitset Library - flip() Function



Description

The C++ function std::bitset::flip() toggles all bits from bitset.

Declaration

Following is the declaration for std::bitset::flip() function form std::bitset header.

C++98

 bitset& flip(); 

C++11

 bitset& flip() noexcept; 

Parameters

None

Return value

Returns this pointer.

Exceptions

This member function never throws exception.

Example

The following example shows the usage of std::bitset::flip() function.

 #include <iostream> #include <bitset> using namespace std; int main(void) { bitset<4> b("1010"); cout << "Before flip operation b = " << b << endl; b.flip(); cout << "After flip operation b = " << b << endl; return 0; } 

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

 Before flip operation b = 1010 After flip operation b = 0101 
bitset.htm
Advertisements