Every time I send a char to the cout object, it displays in ASCII characters unless I cast it to an int.
Q: Is there a way to display the numerical value of a char without an explicit cast?
I read somewhere that doing too many casts in your code could lead to a loss of integrity (of your program). I am guessing that chars display in ASCII for a particular reason, but I'm not sure why.
I am essentially creating a game. I am using small numbers (unsigned chars) that I plan to display to the console. I may be paranoid, but I get this uneasy feeling whenever I spam static_cast<int>
everywhere in my code.
int
instead ofunsigned char
? You're not using chars it to save memory, aren't you? – Hackberry<<
is well-defined and broadly understood. To convertchar
toint
to feed it to a stream is standard technique. There is no threat to integrity here. – Lock