c - 标识符“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]".
我害怕前进,因为我不想搞砸任何事情。
请指教,谢谢。
解决方案
只需#include<stdio.h>
在第一行包含 the ,因为gets()
andputs()
已在头文件中声明stdio.h
#include<stdio.h>
int main()
{
puts("Greetings, human!");
return(0);
}
注意 - 即使在 <stdio.h> 中声明了 gets(),你也不应该使用它。它被从标准 C 中删除是有充分理由的。它不能安全使用
推荐阅读
- agora.io - 如何获得频道中所有用户的“静音”状态?[agora.io]
- python - 从 ftp 服务器下载包含文件的文件夹
- kedro - Kedro 使用字典而不是 parameter.yml
- mongodb - 如何与数组中匹配的值聚合然后排序
- amazon-web-services - AWS Step Functions - 捕获错误时如何忽略“ResultSelector”?
- mongodb - 注册:mongo db根据查询错误输出
- python - 在 QAbstractTableModel 中设置“角色”
- c# - 如何从用户输入打印数组?
- python - 如何在Django中动态显示下拉菜单中的菜单名称
- c# - 应用程序工作并冻结时更改表单