itoa函数实现

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

// 将整数转换成字符串数,不用函数itoa
// 思路:采用加'0',然后在逆序的方法
#include <iostream>
using namespace std;
int main ()
{
    int num = 12345, i = 0, j =0;
    char temp[7], str[7];
    while (num)
    {
        temp[i++] = num % 10 + '0';
        num /= 10;
    }
    temp[i] = '';
    cout << temp << endl;
    i--;
    while (i >= 0)
    {
        str[j++] = temp[i--];
    }
    str[j] = '';
    cout << str << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/simplepaul/p/6760496.html