perror
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <stdio.h> で定義
|
||
void perror( const char *s ); |
||
システム変数 errno に現在格納されているエラーコードの説明テキストを stderr に出力します。
説明は以下の内容を連結することによって形成されます。
sの指すヌル終端バイト文字列の内容に": "が続いたもの (sがヌルポインタでなく、sの指す文字がヌル文字でない場合のみ)。errnoに格納されているエラーコードを説明する処理系定義のエラーメッセージ文字列に'\n'が続いたもの。 このエラーメッセージ文字列はstrerror(errno)の結果と同一です。
引数
| s | - | 説明メッセージを持つヌル終端文字列を指すポインタ |
戻り値
(なし)
例
Run this code
#include <stdio.h>
int main(void)
{
FILE *f = fopen("non_existent", "r");
if (f == NULL) {
perror("fopen() failed");
} else {
fclose(f);
}
}
出力:
fopen() failed: No such file or directory
参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.21.10.4 The perror function (p: 339)
- C99 standard (ISO/IEC 9899:1999):
- 7.19.10.4 The perror function (p: 305)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.9.10.4 The perror function
関連項目
(C11)(C11) |
指定されたエラーコードのテキストバージョンを返します (関数) |
perror の C++リファレンス
| |