举例:
string s1;
int a=7896;
怎么让s1的每一项变成'7','8','9','6'?
char s2[2020];
itoa(a,s2, 10);
然后怎么求s2数组的非空长度?
举例:
string s1;
int a=7896;
怎么让s1的每一项变成'7','8','9','6'?
char s2[2020];
itoa(a,s2, 10);
然后怎么求s2数组的非空长度?
string to_String(int n)
{
int m = n;
char s[max];
char ss[max];
int i=0,j=0;
if (n < 0)// 处理负数
{
m = 0 - m;
j = 1;
ss[0] = '-';
}
while (m>0)
{
s[i++] = m % 10 + '0';
m /= 10;
}
s[i] = '\0';
i = i - 1;
while (i >= 0)
{
ss[j++] = s[i--];
}
ss[j] = '\0';
return ss;
}
用法
int a = 7896;
string s1 = to_String(a);
求字符串长度?
用 strlen(s2);