bitset - STL C++

bitset<N>:::operator[]()

Declaration

bitset<N>::reference bitset<N>::operator[](size_t qIndex);

Description

This is the member function operator[]() for the bitset class template. This function returns the bit value of the bitset at "qIndex."

Header Include

#include <bitset>

Overloads

bool bitset<N>::operator[](size_t qIndex) const;

Example

#include <bitset>
#include <iostream>

int main()
{
	using namespace std;

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

	// Get and set the value at the index [2]
	cout << "The bit value at [2] is " << qBits[2] << endl;
	qBits[2] = false;
	cout << "The bit value at [2] is " << qBits[2] << endl;

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

Output

bitset<N>::operator[]() Output
 

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