### Converting string to hex 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? use `iota` function How about the hex manipulator?

http://www.cplusplus.com/reference/ios/hex/
Last edited on programmer007,
I'm not sure how this would help me.
koothkeeper,
How do I use it to assign something to something else? This is probably overkill but:
 ``123456789101112131415161718`` ``````#include #include #include 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 Thank you.
But I have a problem.
 ``1234567891011121314151617181920`` ``````for (int i = 0; i < numbers.size(); i++) { cout << numbers[i] << " "; } //6 67 9 0 cout << endl; int iTemp; stringstream is, hs; for (int i = 0; i < numbers.size(); i++) { is << numbers[i]; is >> iTemp; // convert string to int hs << std::hex << iTemp; // push int through hex manipulator numbers[i] = hs.str(); } for (int i = 0; i < numbers.size(); i++) { cout << numbers[i] << " "; } //6 66 666 6666 `````` Move line 8 into your loop. Or clear the streams at the end of your loop. Thank you all.
I'd be grateful if someone link me some good sources of stringstream examples.
Topic archived. No new replies allowed.