数字转字符串实现

int convert(char buf[], int value)
{
    constexpr char digits[] = {'9', '8', '7', '6', '5', '4', '3', '2', '1', '0',
                               '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    const char* zero = digits + 9;
    int   i = value;
    char* p = buf;
    do{
        int pushed_nunmber_index = i % 10;
        i /= 10;
        *p++ = zero[pushed_nunmber_index];
    }while(i != 0);
    if (value < 0){
        *p++ = '-';
    }
    *p = '';
    std::reverse(buf, p);
    return static_cast<int>(p - buf);
}
原文地址:https://www.cnblogs.com/wuOverflow/p/5186579.html