itoa函数实现

时间:2024-01-16 12:05:08

1.      整数字符转化为字符串数

// 将整数转换成字符串数,不用函数itoa
// 思路:采用加'0',然后在逆序的方法
#include <iostream>
using namespace std;
int main ()
{
int num = , i = , j =;
char temp[], str[];
while (num)
{
temp[i++] = num % + '';
num /= ;
}
temp[i] = '\0';
cout << temp << endl;
i--;
while (i >= )
{
str[j++] = temp[i--];
}
str[j] = '\0';
cout << str << endl;
return ;
}