#include <iostream>
using namespace std;
思想是一个整数加上'0'自动变成字符型,注意然后要输出
void main()
{
int num = 12345;
int i = 0,j = 0;
char temp[6],str[6],string[6];
itoa(num,string,10);
//string[5] = 0;
printf("num = %d/n string = %s/n",num,string);
while(num)
{
temp[i] = num%10+'0';
i++;
num = num/10;
}
temp[i] = 0, //字符串结尾加0
printf("temp = %s/n",temp); //遇到字符串结尾0结束输出
i = i-1;
while(i>=0)
{
str[j++] = temp[i--];
}
str[j] = 0;
printf("str = %s/n",str);
}
#include <iostream>
using namespace std;
void main()
{
int num = 0,i=0;
char str[6] = {"12345"};
printf("str = %s/n",str);
printf("str[5] = %d/n",str[5]);
printf("length = %d/n",strlen(str));
while(str[i])
{
num = num*10 + str[i]-'0';
i++;
}
printf("num = %d/n",num);
}
//字符串有多种赋值方式
// str[6] = {'1','2','3','4','5'};
// str[6] = {"12345"}
// str[6] = "12345" //字符串数组会自动在尾部加个/0