Int sprintf (char * buffer, const char * format [, argument]...);
<Stdio. h>
For example:
Int ss;
Char temp [64];
String str;
Ss = 1000;
Sprintf (temp, "% d", ss );
String s (temp );
// Call the string method
Cout <s. c_str () <endl; // 1000
Cout <s. size () <endl; // The length is 4
2. char * _ itoa (int value, char * string, int radix );
<Stdlib. h>
For example:
Char buffer [20];
Int I = 3445;
_ Itoa (I, buffer, 10 );
String s (buffer );
3. stringstream ()
<Sstream. h>
For example:
Int hello = 4;
Stringstream ss;
Ss
String s = ss. str ();
// Call the string method
Cout <s. c_str () <endl;
You can also write functions by yourself:
String int2str (int num)
{
If (num = 0)
Return "0 ";
String str = "";
Int num _ = num> 0? Num:-1 * num;
While (num _)
{
Str = (char) (num _ % 10 + 48) + str;
Num _/= 10;
}
If (num <0)
Str = "-" + str;
Return str;
}
Int sprintf (char * buffer, const char * format [, argument]...);
<Stdio. h>
For example:
Int ss;
Char temp [64];
String str;
Ss = 1000;
Sprintf (temp, "% d", ss );
String s (temp );
// Call the string method
Cout <s. c_str () <endl; // 1000
Cout <s. size () <endl; // The length is 4
2. char * _ itoa (int value, char * string, int radix );
<Stdlib. h>
For example:
Char buffer [20];
Int I = 3445;
_ Itoa (I, buffer, 10 );
String s (buffer );
3. stringstream ()
<Sstream. h>
For example:
Int hello = 4;
Stringstream ss;
Ss
String s = ss. str ();
// Call the string method
Cout <s. c_str () <endl;
You can also write functions by yourself:
String int2str (int num)
{
If (num = 0)
Return "0 ";
String str = "";
Int num _ = num> 0? Num:-1 * num;
While (num _)
{
Str = (char) (num _ % 10 + 48) + str;
Num _/= 10;
}
If (num <0)
Str = "-" + str;
Return str;
}