整数转换成字符串(大数会用到滴)
1 #include <iostream> 2 #include <complex> 3 using namespace std; 4 5 void main() 6 { 7 int temp,num,i=0; 8 char c[20]; 9 cout<<"请输入整数"<<endl; 10 cin>>num; 11 temp=num; 12 13 while(temp!=0) 14 { 15 c[i]=temp%10+'0'; 16 i++; 17 temp/=10; 18 } 19 cout<<"字符串为"<<endl; 20 for (int j=i-1;j>=0;j--) 21 { 22 cout<<c[j]; 23 } 24 cout<<endl; 25 }
这个只是最基本的 长度一长就会有问题~主要是取余跟取商转换成字符串的思想值得借鉴~还有加'0'~