Having a dedicated manipulator would close that gap and would eliminate the current "trick" of using
. The (abbreviated) example in cppreference .com reads:
#include <iostream>
#include <sstream>
int main()
{ // This yields 101010
std::cout << "The number 42 in binary: " << std::bin << 42 << '\n';
}
It would also take advantage of other manipulators, like std::setw and std::setfill:
#include <iostream>
#include <sstream>
int main()
{ // This yields 00101010
std::cout << std::setw(8) << std::setfill('0'); std::cout << "The number 42 in binary: " << std::bin << 42 << '\n';
}
Reading binary numbers would also be addressed by the input streams.
IF this proposal is considered, I see changes in:
- A new bin flag in ios_base::basefield.
- Support for the flag in ios_base::setf, ios_base::unsetf and ios_base::flags member functions.
- Creation of the manipulator (similar to other manipulators) for the different char_traits
- Support for binary parsing for input streams
- Support for binary output for ostreams.
std::ios_base in cppreference.com:
https://en.cppreference.com/w/cpp/io/ios_base
Integer I/O manipulators
https://en.cppreference.com/w/cpp/io/manip/hex
Regards,
—Javier