Qbasicnews.com

Full Version: C/C++ int to string?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
That works if you want an STL string, but if you just want a standard char array, you can do something like this:

Code:
char s[20];
int x = 23;
sprintf(s, "%d", x);

Although you probably wouldn't need that big of a buffer... Smile
if your using C++.. I don't see why you wouldn't use STL, I mean, you can easily convert back and forth between string and char *..

char * cstr = str.c_str();
string str = string(cstr);
Oh, thanks. That's helpful, because I've been converting from string to char* using the data() method, which only returns a const char*, so I go through and copy the string data to another non-const char* until I hit a null char... Yay! Less code. Smile
Pages: 1 2