有一个名为itoa.cpp的示例c文件,如下所示:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
char buffer [33];
printf ("Enter a number: ");
scanf ("%d",&i);
itoa (i,buffer,10);
printf ("decimal: %s\n",buffer);
return 0;
}
当我使用以下命令编译时:
gcc itoa.cpp -o itoa
得到了这个错误:
[root@inhyuvelite1 u02]# gcc itoa.cpp -o itoa
itoa.cpp: In function "int main()":
itoa.cpp:10: error: "itoa" was not declared in this scope
发布于 2018-02-11 10:09:44
Itoa不是Ansi C标准。如果真的想要使用它,可以尝试:
http://www.strudel.org.uk/Itoa/
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
char buffer [33];
printf ("Enter a number: ");
scanf ("%d",&i);
snprintf(buffer, sizeof(buffer), "%d", i);
printf ("decimal: %s\n",buffer);
return 0;
}
https://stackoverflow.com/questions/-100007379
复制相似问题