Environment: Dev-C ++
Source code:
# Include <iostream>
# Include <cstdlib>
Using namespace STD;
Main ()
{
Int I1 = 123, I2, I3;
Float F1;
Char c1 [20] = "234.45", C2 [20];
String S1 = "456", S2;
I2 = atoi (C1); // convert the character array to an integer
F1 = atof (C1); // converts a character array to a floating point type
ITOA (I1, C2, 10); // converts an integer to a character array. 10 indicates a decimal number.
Cout <"character array converted to integer:" <I2 <Endl;
Cout <"character array converted to floating point type:" <F1 <Endl;
Cout <"integer converted to character array:" <C2 <Endl;
Strncpy (C2, s1.c _ STR (), s1.length (); // convert a string to a character array
I3 = atoi (C2 );
Cout <"string converted to integer:" <I3 <Endl;
System ("pause ");
}
:
From http://hi.baidu.com/isokill/blog/item/7e0620d6146f11c9a8ec9a5a.html