头文件
#include <stdio.h>
perror函数
void perror(const char *s);
例如:perror("helloworld")
perror是用来将上一个函数的错误原因输出到标准设备stderr。参数s所指的字符串先打印然后加上错误原因字符串。
#include <stdio.h>
int main()
{
FILE *fp;
if((fp = fopen("helloworld.txt","r")) == 0)
{
perror("helloworld");
}
return 0;
}
样例输入输出:
helloworld: No such file or directory

本文介绍C语言中perror函数的基本用法及其应用场景。通过一个简单的示例程序展示了如何使用perror函数来报告文件打开失败的具体原因,并将错误信息输出到标准错误设备stderr。

834

被折叠的 条评论
为什么被折叠?



