operator<<,>>(std::bitset) (3) - Linux Manuals
operator<<,>>(std::bitset): operator<<,>>(std::bitset)
NAME
operator<<,>>(std::bitset) - operator<<,>>(std::bitset)
Synopsis
template <class CharT, class Traits, size_t N>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, (1)
const bitset<N>& x);
template <class CharT, class Traits, size_t N>
std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, (2)
bitset<N>& x);
Inserts or extracts a bitset from a character stream.
1) Writes the bitset x to the character stream os as if by first converting it to a basic_string<CharT,Traits> using to_string(), and then writing it into os using the operator<< (which is a FormattedOutputFunction for strings). The characters to use for ones and zeroes are obtained from the currently-imbued locale by calling std::use_facet<std::ctype<CharT>(os.getloc()).widen() with '1' and '0' as arguments.
2) Behaves as a FormattedInputFunction. After constructing and checking the sentry object, which may skip leading whitespace, extracts up to N characters from is and stores the characters in the bitset x.
Characters are extracted until either
* N characters have been read,
* end-of-file occurs in is, or
* the next character is neither is.widen('0') nor is.widen('1').
If no characters are extracted, is.setstate(ios_base::failbit) is called.
Parameters
os - the character stream to write to
is - the character stream to read from
x - the bitset to be read or written
Return value
The character stream that was operated on, e.g. os or is.
Example
// Run this code
Output:
See also
operator<<= performs binary shift left and shift right
operator>>= (public member function)
operator<<
operator>>