Inserts or extracts a bitset from a character stream.
2)Behaves as a
FormattedInputFunction. After constructing and checking the sentry object, which may skip leading whitespace, extracts up to
Ncharacters from
isand stores the characters in the bitset
x.
Characters are extracted until either
If
N > 0and no characters are extracted,
is.setstate(ios_base::failbit)is called.
[edit] Parameters os - the character stream to write to is - the character stream to read from x - the bitset to be read or written [edit] Return value1) os
2) is
[edit] Example#include <bitset> #include <iostream> #include <sstream> int main() { std::string bit_string = "001101"; std::istringstream bit_stream(bit_string); std::bitset<3> b1; bit_stream >> b1; // reads "001", stream still holds "101" std::cout << b1 << '\n'; std::bitset<8> b2; bit_stream >> b2; // reads "101", populates the 8-bit set as "00000101" std::cout << b2 << '\n'; }
Output:
[edit] Defect reportsThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 303 C++98 single-byte characters were extracted fromCharT
can have multiple bytes extracts CharT
and compares
std::bitset<0>
always sets failbit
such extraction never sets failbit
[edit] See also
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