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