You can't. uint8_t
and int8_t
are typedefs for unsigned char
and signed char
respectively. These types are treated as character types by iostreams and there's no way to change that behaviour.
Your second example is really the only way you can do this.