看起来这应该很简单,但我没有在网络搜索中找到它.
我有一个ofstream的是open(),而且fail()现在是真实的.我想知道失败的原因,就像errno我会这样做sys_errlist[errno].
Nat*_*ohl 19
该字符串错误的功能<cstring>可能是有用的.这不一定是标准的或可移植的,但它对我在Ubuntu盒子上使用GCC没问题:
#include <iostream>
using std::cout;
#include <fstream>
using std::ofstream;
#include <cstring>
using std::strerror;
#include <cerrno>
int main() {
ofstream fout("read-only.txt"); // file exists and is read-only
if( !fout ) {
cout << strerror(errno) << '\n'; // displays "Permission denied"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15272 次 |
| 最近记录: |