Accesses the bit at position pos.
1) Returns the value of the bit.
If pos < size() is false, the behavior is undefined.
(until C++26)If pos < size() is false:
1) The value of the requested bit.
[edit] ExceptionsThrows nothing.
[edit] Example#include <bitset> #include <cstddef> #include <iostream> 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, b1 holds " << b1 << '\n'; }
Output:
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, b1 holds 00101011[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 11 C++98 1. the description was missing in the C++ standardtest(pos)
, but test()
may throw exceptions avoids mentioning test()
[edit] See also accesses specific bit
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4