I want to control whether my ostream
outputting of char
s and unsigned char
's via <<
writes them as characters or integers. I can't find such an option in the standard library. For now I have reverted to using multiple overloads on a set of alternative print functions
ostream& show(ostream& os, char s) { return os << static_cast<int>(s); }
ostream& show(ostream& os, unsigned char s) { return os << static_cast<int>(s); }
Is there a better way?
ios
state flags. – Liggittcout << static_cast<uint32_t>(some_char_val);
? – Mendelsohnuint64_t
to minimize risk of overflow but what if argument is an arbitrary precision integer or some other class no convertible touintxx_t
? – Liggittchar
s andunsigned char
s. – Mendelsohn