Home C&C++函数库 c++ 语法 程序源码 Linux C库

strerror

函数   <cstring>

char * strerror ( int errnum );


获取指向错误消息字符串的指针

解析errnum的值,生成一个带有描述错误条件的消息的字符串,就像被库的函数设置为errno一样。

返回的指针指向一个静态分配的字符串,程序不能修改该字符串。
对这个函数的进一步调用可能会覆盖它的内容(不需要特定的库实现来避免数据竞争)。

strerror产生的错误字符串可能是特定于每个系统和库实现的。

☲  参数


errnum
错误代码

☉  返回值



指向描述错误errnum的错误字符串的指针。

☣  示例



/* strerror example : error list */
#include <stdio.h>
#include <string.h>
#include <errno.h>

int main ()
{
  FILE * pFile;
  pFile = fopen ("unexist.ent","r");
  if (pFile == NULL)
    printf ("Error opening file unexist.ent: %s\n",strerror(errno));
  return 0;
}



可能的输出:
Error opening file unexist.ent: No such file or directory

🍄  另请参阅



errno 最终错误码(宏)
perror 打印错误信息(function )

联系我们 免责声明 关于CandCplus 网站地图