1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int num = 12345, j = 0, i = 0; 6 char temp[7], str[7]; 7 8 while (num) 9 { 10 temp[i] = num % 10 + '0'; 11 i++; 12 num = num / 10; 13 } 14 temp[i] = 0; 15 printf("temp=%s ", temp); 16 i = i - 1; 17 printf("temp=%d ", i); 18 while (i >= 0) 19 { 20 str[j] = temp[i]; 21 j++; 22 i--; 23 } 24 str[j] = 0; 25 printf("string=%s ", str); 26 system("PAUSE"); 27 return 0; 28 }
#include<iostream> using namespace std; int main (void) { int num = 100; char str[25]; itoa(num, str, 10); cout<<num<<" "<<str; return 0; }
itoa()函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转移数字时所用的基数。在上例中,转换基数为10。10:十进制;2:二进制...