GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::bitset::operator[](3) C++ Standard Libary std::bitset::operator[](3)

std::bitset::operator[] - std::bitset::operator[]


bool operator[]( std::size_t pos ) const; (until C++11)
constexpr bool operator[]( std::size_t pos ) (since C++11)
const; (1)
reference operator[]( std::size_t pos ); (until C++23)
constexpr reference operator[]( std::size_t pos (2) (since C++23)
);


Accesses the bit at position pos. The first version returns the value of the bit,
the second version returns an object of type std::bitset::reference that allows
modification of the value.


Unlike test(), does not throw exceptions: the behavior is undefined if pos is out of
bounds.


pos - position of the bit to return


1) the value of the requested bit


2) an object of type std::bitset::reference, which allows writing to the requested
bit.


None

// Run this code


#include <iostream>
#include <bitset>


int main()
{
std::bitset<8> b1{0b00101010}; // binary literal for 42


for (std::size_t i = 0; i < b1.size(); ++i) {
std::cout << "b1[" << i << "]: " << b1[i] << '\n';
}
b1[0] = true; // modifies the first bit through bitset::reference


std::cout << "After setting bit 0, the bitset holds " << b1 << '\n';
}


b1[0]: 0
b1[1]: 1
b1[2]: 0
b1[3]: 1
b1[4]: 0
b1[5]: 1
b1[6]: 0
b1[7]: 0
After setting bit 0, the bitset holds 00101011


test accesses specific bit
(public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.