[Solved, but I still have a question] C++ Question re assigning int to another var as hex | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

[Solved, but I still have a question] C++ Question re assigning int to another var as hex

I understand how to convert an int (or multiple var) to hex using std::hex during output (cout) int x = 123; cout << hex << x; but how would one instead assign the hex value to a different variable, like y? Solved: int x = 123; stringstream ss; ss << hex << x; string y = ss.str(); Out of curiosity, if one wanted to convert multiple int is there a strategy aside from repaying this many times? Perhaps a loop, but in that case how would one keep reassigning the in and out variable names?

29th Nov 2022, 10:50 PM
Scott D
Scott D - avatar
2 Antworten
+ 2
you need use loop and probably a array of stringstreams
30th Nov 2022, 12:24 AM
Giannis
Giannis - avatar
0
Giannis I'm thinking you could be right. If going straight to cout one sstream might do but to place each int to a different hex var is likely a different story. Still you think there would be a way to do it with large amounts of integers... maybe looping into an array? Or vectors? (I know *nothing* about vectors yet except they exist 🙄).
30th Nov 2022, 4:42 AM
Scott D
Scott D - avatar