perror
- 作用:将上一个函数发生的错误原因,输出到标准设备.
- C++中的errno变量,是用来记录错误类型。当调用,某些函数出错时,会自动设置errno的值。此时,可以利用perror,将errno错误输出。
- 代码
// 头文件
#include <stdio.h>
/* 函数原型
* 参数str,指定要输出的字符串
* 如 perror("Error:")
* 输出 Error: error message
*/
void perror (const char* str)
// 例子
#include <stdio.h>
int main()
{
FILE* fp;
fp = fopen("/xxx/xxx", "r+");
if (NULL == fp) {
perror("Error: ");
}
return 0;
}