bitset - STL C++

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

Declaration

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

Description

This is the operator bool() member function for the class reference that is a nested class inside the bitset class template. This function returns the bool that is converted from the bit of the bitset designated by the reference.

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;

	// Output each converted boolean value
	cout << "qBits[0] = "<< (bool)(qBits[0]) << endl;
	cout << "qBits[1] = "<< (bool)(qBits[1]) << endl;
	cout << "qBits[2] = "<< (bool)(qBits[2]) << endl;
	cout << "qBits[3] = "<< (bool)(qBits[3]) << endl;

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

Output

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

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