Hexwert von char in string
-
Hallo,
habe folgendes Problem:
Ich habe ein char von dem ich den hexwert (bsp. 0x2c) als string brauche. Habe keine Ahnung wie ich da rankomme. Weiß jemand Rat?Vielen Dank schonmal
-
(
char abc = 0x2c;bzw
std::string abc(0x2c);?
Oder suchst du was anderes?)Jetzt hab ichs geblickt:
in C++ nimmst du einen istringstream und operator<<(), den char wandelst du in int umint i = mychar;und bei der ausgabe musst du halt angeben dass er das in Hex ausgeben soll:
mystringsrteam << io_base::hex << i << endl;mit mystringstream.str() kommst du dann wieder an einen std::string.
namespace std:: beachten!
-
Danke, so klappts

-
Und dafür brauchst du noch nicht einmal eine Vollwert-Variable anlegen:
mystringsrteam << io_base::hex << (int)mychar;