C++中的详细文件IO错误报告 有任何开源文件IO库或C++中的简单方法,它报告文件IO的细节和精确错误。例如,;如果用户没有读取或权限,或者磁盘已满等。

C++中的详细文件IO错误报告 有任何开源文件IO库或C++中的简单方法,它报告文件IO的细节和精确错误。例如,;如果用户没有读取或权限,或者磁盘已满等。,c++,file-io,c++11,C++,File Io,C++11,C风格的文件操作默认执行此操作,您只需包括cerrorno和cstring,并在文件操作调用失败后使用: hFile = fopen(fname, "r+b"); /*-- attempt to create the file if we can't open it for reading --*/ if(!hFile) { /*-- print out relevant error information --*/ printf("Open File %s Failed, %s

C风格的文件操作默认执行此操作,您只需包括cerrorno和cstring,并在文件操作调用失败后使用:

hFile = fopen(fname, "r+b");
/*-- attempt to create the file if we can't open it for reading --*/
if(!hFile) {
    /*-- print out relevant error information --*/
    printf("Open File %s Failed, %s\n", fname, std::strerror(errno));
    return 1;
}
return 0;
当然,如果您使用C风格的文件操作,就需要这样做。我认为ifstream在大多数编译器上也支持这些

请注意,在某些实现中,此功能不是线程安全的。linux上有一个线程安全的