我有一个使用 ofstream 写入其输出的程序。使用 Visual Studio 编译时,在 Windows 上一切正常,但使用 GCC 编译时,它只会在 Linux 上写入空文件。
ofstream out(path_out_cstr, ofstream::out);
if(out.bad()){
cout << "Could not write the file" << flush;
}
else{
cout << "writing";
out << "Content" << endl;
if(out.fail()) cout << "writing failed";
out.flush();
out.close();
}
正在写入的目录具有 0777 权限。
奇怪的是:什么都没写,却没有报错。
gcc --version 是: (Gentoo 4.3.4 p1.0, pie-10.1.5) 4.3.4
我知道代码应该工作,所以我更喜欢寻找建议,可能是错的,而不是直接代码修复。
编辑: fwrite 似乎以完全相同的方式失败(没有任何内容,没有报告错误)。
编辑:我正在我的大学目录上通过 SSH 执行 GCC 和程序,如果它有任何意义的话。我有足够的权限来执行和写入文件(ls .> out.txt 工作得很好),只有我的程序有问题。
感谢帮助