perror

来自cppreference.com
< cpp | io | c
跳转到: 导航, 搜索

语法:

    #include <cstdio>
    void perror( const char *str );

perror()函数打印str和实现定义的、与全局变量errno相关的错误信息。例如:

    char* input_filename = "not_found.txt";
    FILE* input = fopen( input_filename, "r" );
    if( input == NULL ) {
      char error_msg[255];
      sprintf( error_msg, "Error opening file '%s'", input_filename );
      perror( error_msg );
      exit( -1 );
    }

如果文件not_found.txt没有找到,这段代码将产生如下输出:

    Error opening file 'not_found.txt': No such file or directory

相关主题: clearerr, feof, ferror, [[cpp/../string/strerror | strerror]]

个人工具
名字空间
操作
导航
工具箱
其他语言