-
Integer to string?
Ok - I'm trying to turn an integer into a string.
Say I have 203. I want it to become "203". I cant really think of any way to do this. My first idea was disasembling the integer and take it byte by byte. But I'm not quite sure how to do that, so my next idea was just say
Code:
char test=2238;
string the;
the+=test;
But it ends up as some odd letter, it probably just cycles through 255 until it finds the value. (255, 510, 765, ect)
I looked online, it gave me some libraries, but no code to solve it. I thought the idea was simple enough - I guess not.
So, is their an easy way to cast an integer to a string? Vice versa is much easier, as you can dissasemble a string.
-
You can use stringstreams with #include <sstream>
e.g.
Code:
int num = 203;
std::string str;
std::stringstream ss;
ss << num;
ss >> str;
//now str contains "203"
-