///用itoa将整数转换成字符串
#include<iostream>
using namespace std;
//int main(void)
//{
// int n=1234567;
// char str[10];
// itoa(n,str,10);
// cout<<"n="<<n<<" str="<<str<<endl;
// return 0;
//}
///直接将整数转换成字符串
//int main(void)
//{
// int num=1234567;
// char temp[10],str[10];
// int i=0;
// while(num)
// {
// temp[i]=num%10+'0';
// i++;
// num/=10;
// }
// temp[i]=0;//结束符,且是倒序
// cout<<temp<<endl;//先输出来看看
// i=i-1;//从最后一个数字那里开始,而不是结束符那里给倒序过来
// int j=0;
// while(i>=0)
// {
// str[j]=temp[i];
// j++;
// i--;
// }
// temp[j]=0;
// cout<<str<<endl;
// return 0;
//}
/字符串转换成int
int main(void)
{
int sum=0;//字符串转换的整数
char temp[10]={'1','2','3','4','5','6','7','\0'};
int i=0;
while(temp[i])
{
sum=sum*10+(temp[i]-'0');
i++;
}
cout<<sum<<endl;
return 0;
}
#include<iostream>
using namespace std;
//int main(void)
//{
// int n=1234567;
// char str[10];
// itoa(n,str,10);
// cout<<"n="<<n<<" str="<<str<<endl;
// return 0;
//}
///直接将整数转换成字符串
//int main(void)
//{
// int num=1234567;
// char temp[10],str[10];
// int i=0;
// while(num)
// {
// temp[i]=num%10+'0';
// i++;
// num/=10;
// }
// temp[i]=0;//结束符,且是倒序
// cout<<temp<<endl;//先输出来看看
// i=i-1;//从最后一个数字那里开始,而不是结束符那里给倒序过来
// int j=0;
// while(i>=0)
// {
// str[j]=temp[i];
// j++;
// i--;
// }
// temp[j]=0;
// cout<<str<<endl;
// return 0;
//}
/字符串转换成int
int main(void)
{
int sum=0;//字符串转换的整数
char temp[10]={'1','2','3','4','5','6','7','\0'};
int i=0;
while(temp[i])
{
sum=sum*10+(temp[i]-'0');
i++;
}
cout<<sum<<endl;
return 0;
}