H
Huyvtq
What's the function I can use ?? Help me!
Thanks.
Thanks.
Huyvtq said:What's the function I can use ?? Help me!
Thanks.
Jim said:The best choice, IMO, is to use a stringstream.
std::stringstream Convert;
Convert << 12345;
std::string NumAsString;
Convert >> NumAsString;
...
JeffCameron said:#include <stdio.h>
#include said:#include <string>
...
int number;
char s1[256];
number = 42;
sprintf(s1, "%d", number);
std::string s = new std::string(s1);
JeffCameron said:#include <stdio.h>
#include <string>
...
int number;
char s1[256];
number = 42;
sprintf(s1, "%d", number);
std::string s = new std::string(s1);
Thomas J. Gritzan said:JeffCameron said:#include <stdio.h>
#include <string>
...
int number;
char s1[256];
number = 42;
sprintf(s1, "%d", number);
std::string s = new std::string(s1);
Will not compile.
"new std::string" returns a pointer.
Jim said:The best choice, IMO, is to use a stringstream.
std::stringstream Convert;
Convert << 12345;
std::string NumAsString;
Convert >> NumAsString;
At this point the std::string Convert will contain "12345".
Another, although I feel poorer choice, is itoa which uses char arrays
rather than std::string.
int number;
char s1[256];
number = 42;
sprintf(s1, "%d", number);
Grizlyk said:JeffCameron ÐÉÓÁÌ(Á):
int number;
char s1[256];
number = 42;
sprintf(s1, "%d", number);
snprintf can be used (if implemented) as safe version of sprintf
Greg said:In a conforming C++ implementation, std::snprintf() will always be
implemented.
The routine is declared in <cstdio>.
Greg said:Of course snprintf() is not perfectly safe either, since a buffer
overrun - while less likely - is still possible.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.