strerror
strerror
通過標準錯誤的標號,獲得錯誤的描述字元串,將單純的錯誤標號轉為字元串描述,方便用戶查找錯誤。
strerror, _strerror, _wcserror, __wcserror
Get a system error message (strerror, _wcserror) or prints a user-supplied error message (_strerror, __wcserror).
獲取系統錯誤信息或列印用戶程序錯誤信息。
參數:
Error number.
strErrMsg
User-supplied message.
返回:
指向錯誤信息的指針(即:錯誤的描述字元串)。
例一:
輸出:
error=2
Mesg:No such file or direcory
例二:
// crt_perror.c
// compile with: /W1
#include
#include
#include
#include
#include
#include
#include
int main( void )
{
int fh;
if( _sopen_s( &fh, "NOSUCHF.ILE", _O_RDONLY, _SH_DENYNO, 0 ) != 0 )
{
perror( "perror says open failed" );
printf( "strerror says open failed: %s\n",
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\n" );
_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