名稱空間
變體
操作

std::perror

來自 cppreference.com
< cpp‎ | io‎ | c
 
 
 
 
定義於標頭檔案 <cstdio>
void perror( const char *s );

將當前儲存在系統變數 errno 中的錯誤程式碼的文字描述列印到 stderr

描述由以下部分組成:

  • 指向 s 所指向的空終止位元組字串的內容,後跟 ": "(除非 s 是空指標或 s 所指向的字元是空字元)。
  • 實現定義的錯誤訊息字串,描述儲存在 errno 中的錯誤程式碼,後跟 '\n'。錯誤訊息字串與 std::strerror(errno) 的結果相同。

目錄

[編輯] 引數

s - 指向帶有解釋性訊息的空終止字串的指標

[編輯] 返回值

(無)

[編輯] 示例

#include <cerrno>
#include <cmath>
#include <cstdio>
 
int main()
{
    double not_a_number = std::log(-1.0);
    if (errno == EDOM)
        std::perror("log(-1) failed");
    std::printf("%f\n", not_a_number);
}

可能的輸出

log(-1) failed: Numerical argument out of domain
nan

[編輯] 另請參閱

擴充套件為 POSIX 相容的執行緒區域性錯誤碼變數的宏
(宏變數)[編輯]
返回給定錯誤程式碼的文字版本
(函式) [編輯]
C 文件 用於 perror