首页 > 解决方案 > 标识符“puts”未定义 C/C++(20) [3,5] 错误

问题描述

我在“C All-in-one Desk Reference for Dummies”一书中有 16 页。我使用 Visual Studio Code 作为编辑器,使用 MinGW 作为编译器。系统提示我编写和编译代码:

int main() 
{
    puts("Greetings, human!");
    return(0);
}

我已经编译过了。两件事由此而来。第一个问题到达终端:

dumb.c:3:5: warning: implicit declaration of function 'puts' [-Wimplicit-function-declaration]
     puts("Greetings, human!");
     ^~~~

第二个出现在输出旁边的(问题)选项卡上,它给了我一个通知,上面写着,"identifier "puts" is undefined C/C++(20) [3,5]".

我害怕前进,因为我不想搞砸任何事情。

请指教,谢谢。

标签: c

解决方案


只需#include<stdio.h>在第一行包含 the ,因为gets()andputs()已在头文件中声明stdio.h

#include<stdio.h>
int main() 
{
    puts("Greetings, human!");
    return(0);
}

注意 - 即使在 <stdio.h> 中声明了 gets(),你也不应该使用它。它被从标准 C 中删除是有充分理由的。它不能安全使用


推荐阅读