小编kin*_*r_e的帖子

ofstream不冲洗

我有以下代码,在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,但它没有用.

有什么建议?

c++ ofstream

9
推荐指数
3
解决办法
1万
查看次数

标签 统计

c++ ×1

ofstream ×1