词条 | strerror |
释义 | 函数名strerror, _strerror, _wcserror, __wcserror 函数作用Get a system error message (strerror, _wcserror) or prints a user-supplied error message (_strerror, __wcserror). 获取系统错误信息或打印用户程序错误信息。 头文件#include <string.h> 函数原型char *strerror( int errnum ); char *_strerror( const char *strErrMsg ); wchar_t * _wcserror( int errnum ); wchar_t * __wcserror( const wchar_t *strErrMsg ); 参数: errnum Error number. strErrMsg User-supplied message. 返回: 指向错误信息的指针。 举例// crt_perror.c // compile with: /W1 /* This program attempts to open a file named * NOSUCHF.ILE. Because this file probably doesn't exist, * an error message is displayed. The same message is * created using perror, strerror, and _strerror. */ #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <io.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <share.h> int main( void ) { int fh; if( _sopen_s( &fh, "NOSUCHF.ILE", _O_RDONLY, _SH_DENYNO, 0 ) != 0 ) { /* Three ways to create error message: */ perror( "perror says open failed" ); printf( "strerror says open failed: %s\", strerror( errno ) ); // C4996 printf( _strerror( "_strerror says open failed" ) ); // C4996 // Note: strerror and _strerror are deprecated; consider // using strerror_s and _strerror_s instead. } else { printf( "open succeeded on input file\" ); _close( fh ); } } 输出: perror says open failed: No such file or directory strerror says open failed: No such file or directory _strerror says open failed: No such file or directory |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。