bitset - STL C++

bitset<N>::flip()

Declaration

bitset<N>& bitset<N>::flip();

Description

This is the member function flip() for the bitset class template. This function flips the value of each bit in the bitset and returns a reference to the bitset. The overloaded version is similar except that it flips a single bit at the position that is passed into the function.

Header Include

#include <bitset>

Overloads

bitset<N>& bitset<N>::flip(size_t qPos);

Example

#include <bitset>
#include <iostream>

int main()
{
	using namespace std;

	// Create a bitset
	bitset<4> qBits(3);
	cout << "bitset<4> : "<< qBits << endl;

	// Call the flip() function to flip the bits.
	qBits.flip();
	cout << "bitset<4> : "<< qBits << endl;

	// Call the flip() function to flip one bit.
	qBits.flip(2);
	cout << "bitset<4> : "<< qBits << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

bitset<N>::flip() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.