Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C/C++ int to string?
#11
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
Reply
#12
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);
COUNT HACKED BY RAZVEEE

RAZVEE IS A SCRIPT KIDDIE- hacker9
Reply
#13
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)