According to some documentation I found for std::bitset:
They can also be directly inserted and extracted from streams in binary format (see applicable operators).
Applicable operators:
is,os basic_istream or basic_ostream object from which a bitset object is respectively extracted or inserted. The format in which bitsets are inserted/extracted is a sequence of (suitably widened) '0' and '1' characters.
template<class charT, class traits, size_t N>
basic_istream<charT, traits>&
operator>> (basic_istream<charT,traits>& is, bitset<N>& rhs);
template<class charT, class traits, size_t N>
basic_ostream<charT, traits>&
operator<< (basic_ostream<charT,traits>& os, const bitset<N>& rhs);
This essentially means that we are allowed to do something like:
std::stringstream _stream(std::ios::binary);
{...}
std::bitset<16> a1;
std::bitset<8> a2;
_stream >> std::bin >> a1;
_stream >> std::bin >> a2;
It seems to me that I just don't have std::bin in the Standard Library, everything else should be ok.
I'm wondering if there is any way to implement this modifier?
std::bin? I've never heard of it.1and0this already works._stream >> a1;without any special IO manipulator likestd::bin(which does not exist). However, the bitsets will be represented by 0s and 1s, stored as characters in the stream. I don't think there is any standard way to get them stored as actual bits.std::bin??std::binin the stl to make the dream come true. @jogojapan I have some binary-oriented data in my stream(let's say there is a binary file) but not prearranged zeroes and ones.