0

I have some code for converting an int to a string

char val = 0x79;

std::stringstream str1, str2;

str1 << std::hex << val;   
str2 << std::hex << (short) val;
std::cout << str1.str() << std::endl;
std::cout << str2.str() << std::endl;

The output is

y    
79

The second output is what I want but I don't like having to cast the char to a short. Is there a way to get the output I want without the cast?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Richard Johnson
  • 612
  • 1
  • 9
  • 20

0 Answers0