|
|
Member types | |||||||||||
Member functions | |||||||||||
(until C++20) | |||||||||||
Element access | |||||||||||
Capacity | |||||||||||
Modifiers | |||||||||||
Conversions | |||||||||||
(C++11) | |||||||||||
Non-member functions | |||||||||||
| |||||||||||
Helper classes | |||||||||||
(C++11) |
Defined in header <bitset> | ||
template<class CharT,class Traits,std::size_t N> std::basic_ostream<CharT, Traits>& | (1) | |
template<class CharT,class Traits,std::size_t N> std::basic_istream<CharT, Traits>& | (2) | |
Inserts or extracts a bitset from a character stream.
Contents |
os | - | the character stream to write to |
is | - | the character stream to read from |
x | - | the bitset to be read or written |
#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:
00100000101
The 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 from is, but CharT can have multiple bytes | extractsCharT and comparesit with widened'0' and'1' |
LWG 396 | C++98 | the content written byoperator<< was locale-independent | writes widened'0's and'1's |
LWG 3199 | C++98 | extracting astd::bitset<0> always setsfailbit | such extraction never setsfailbit |
performs binary shift left and shift right (public member function)[edit] |