bitset - STL C++

bitset<N>::reference::operator~()

Declaration

bool bitset<N>::reference::operator~();

Description

This is the operator~() member function for the class reference that is a nested class inside the bitset class template. This function negates the bit of the bitset designated by the reference and turns it into a bool.

Header Include

#include <bitset>

Example

#include <bitset>
#include <iostream>

int main()
{
	using namespace std;

	// Create a bitset of four bits with the 2nd one "on"
	bitset<4> qBits(2);
	cout << "bitset<4> : "<< qBits << endl;

	// Negate the fourth bit
	bool bNegFourthBit =  ~(qBits[3]);
	cout << "The negation of " << qBits[3] << " is " << bNegFourthBit << endl;

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

Output

bitset<N>::reference::operator~() Output
 

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