how to convert integer into string pointer in visual c++?
This is how I did it in my homework since we were only allowed to use some predetermined libraries. I'm pretty sure it's not considered a "best practice" though ;)
string int2string(int integer) {
string str;
int division = integer;
while (division > 0) {
str = char('0' + (division % 10)) + str;
division = division / 10;
}
return str;
}
search for atoi / itoa in your favorite documentation. Or try Boost (www.boost.org - library Conversion, lexical_cast).
Both ways are portable across different compilers.
Use stringstream
#include <sstream>
stringstream ss;
ss << i;
string s = ss.str();
If you using CString, then you can use Format() method like this:
int val = 489;
CString s;
s.Format("%d", val);