Here´ http://en.wikipedia.org/wiki/Itoa有一些帮助
/* itoa: convert n to characters in s */
void itoa(int n, char s[])
{
int i, sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}
您应该根据您的需要调整它(注意这个有 2 个参数,而不是 3 个)
另请注意,反向函数也位于维基百科链接中。
此外,here http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/还有其他一些情况(但不适用于基数 2)
该函数未在 ANSI-C 中定义
不是 C++ 的一部分,但是
一些编译器支持。
符合标准的替代方案
有些情况可能是 sprintf:
sprintf(str,"%d",value)
转换为十进制基数。
sprintf(str,"%x",value)
转换为十六进制基数。
sprintf(str,"%o",value)
转换为八进制。