Apr 8, 2015 at 1:53pm UTC
Hello. I need to convert string of decimal number to hex. I need the string to remain string (or at least the output to be string). What's the easiest way to do this?
Apr 8, 2015 at 2:00pm UTC
Last edited on Apr 8, 2015 at 2:04pm UTC
Apr 8, 2015 at 2:21pm UTC
programmer007,
I'm not sure how this would help me.
koothkeeper,
How do I use it to assign something to something else?
Apr 8, 2015 at 2:25pm UTC
This is probably overkill but:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <string>
#include <sstream>
int main()
{
std::string iString = "12345" , hString;
int iTemp = 0;
std::stringstream is, hs;
is << iString;
is >> iTemp; // convert string to int
hs << std::hex << iTemp; // push int through hex manipulator
hString = hs.str(); // store hex string
std::cout << "Decimal = " << iString << ", Hex = " << hString << std::endl;
return 0;
}
Last edited on Apr 8, 2015 at 2:26pm UTC
Apr 8, 2015 at 2:52pm UTC
Move line 8 into your loop. Or clear the streams at the end of your loop.
Apr 8, 2015 at 3:21pm UTC
Thank you all.
I'd be grateful if someone link me some good sources of stringstream examples.