operator<<,>>(std::bitset) (3) - Linux Manuals
operator<<,>>(std::bitset): operator<<,>>(std::bitset)
Command to display operator<<,>>(std::bitset)
manual in Linux: $ man 3 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
#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:
001
00000101
See also
operator<<= performs binary shift left and shift right
operator>>= (public member function)
operator<<
operator>>
Pages related to operator<<,>>(std::bitset)
- operator<<,>>(std::binomial_distribution) (3) - operator<<,>>(std::binomial_distribution)
- operator<<,>>(std::basic_string) (3) - operator<<,>>(std::basic_string)
- operator<<,>>(std::bernoulli_distribution) (3) - operator<<,>>(std::bernoulli_distribution)
- operator<<,>>(std::cauchy_distribution) (3) - operator<<,>>(std::cauchy_distribution)
- operator<<,>>(std::chi_squared_distribution) (3) - operator<<,>>(std::chi_squared_distribution)
- operator<<,>>(std::complex) (3) - operator<<,>>(std::complex)
- operator<<,>>(std::discard_block_engine) (3) - operator<<,>>(std::discard_block_engine)
- operator<<,>>(std::discrete_distribution) (3) - operator<<,>>(std::discrete_distribution)
- operator<<,>>(std::experimental::filesystem::path) (3) - operator<<,>>(std::experimental::filesystem::path)
- operator<<,>>(std::exponential_distribution) (3) - operator<<,>>(std::exponential_distribution)
- operator<<,>>(std::extreme_value_distribution) (3) - operator<<,>>(std::extreme_value_distribution)
- operator<<,>>(std::filesystem::path) (3) - operator<<,>>(std::filesystem::path)
- operator<<,>>(std::fisher_f_distribution) (3) - operator<<,>>(std::fisher_f_distribution)
- operator<<,>>(std::gamma_distribution) (3) - operator<<,>>(std::gamma_distribution)
- operator<<,>>(std::geometric_distribution) (3) - operator<<,>>(std::geometric_distribution)
- operator<<,>>(std::independent_bits_engine) (3) - operator<<,>>(std::independent_bits_engine)
- operator<<,>>(std::linear_congruential_engine) (3) - operator<<,>>(std::linear_congruential_engine)
- operator<<,>>(std::lognormal_distribution) (3) - operator<<,>>(std::lognormal_distribution)
- operator<<,>>(std::mersenne_twister_engine) (3) - operator<<,>>(std::mersenne_twister_engine)
- operator<<,>>(std::negative_binomial_distribution) (3) - operator<<,>>(std::negative_binomial_distribution)
- operator<<,>>(std::normal_distribution) (3) - operator<<,>>(std::normal_distribution)
- operator<<,>>(std::piecewise_constant_distribution) (3) - operator<<,>>(std::piecewise_constant_distribution)
- operator<<,>>(std::piecewise_linear_distribution) (3) - operator<<,>>(std::piecewise_linear_distribution)