我有以下代码,在 Suse 10.1 / G++ 4.1.0 上运行,它不写入文件:
#include <fstream>
#include <iostream>
int main(){
std::ofstream file("file.out");
file << "Hello world";
}
该文件已正确创建并打开,但为空。如果我将代码更改为:
#include <fstream>
#include <iostream>
int main(){
std::ofstream file("file.out");
file << "Hello world\n";
}
\n
(在文本中添加一个),它有效。我也试过冲洗ofstream,但没有用。
有什么建议么?