c ++ std :: ofstream flush()但不关闭() [英] c++ std::ofstream flush() but not close()

查看:1445
本文介绍了c ++ std :: ofstream flush()但不关闭()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MacOSX。

在我的应用程序的记录器部分,我将数据转储到文件。

In the logger part of my application, I'm dumping data to a file.

假设我有一个全局声明的 std :: ofstream outFile(log);

suppose I have a globally declared std::ofstream outFile("log");

在我的日志代码中我有:

and in my logging code I have:

outFile << "......." ;
outFile.flush();

现在,假设我的代码在flush在将 flush()保证写入磁盘之前,将这些东西写入 outFile 调用 close())。

Now, suppose my code crashes after the flush() happens; Is the stuff written to outFile before the flush() guaranteed to be written to disk (note that I don't call a close()).

谢谢!

推荐答案

从C ++运行时的角度来看,它应该已经写入磁盘。从操作系统的角度看,它可能仍然在缓冲区,但这只会是一个问题,如果你的整个机器崩溃。

From the C++ runtime's point of view, it should have been written to disk. From an OS perspective it might still linger in a buffer, but that's only going to be an issue if your whole machine crashes.

这篇关于c ++ std :: ofstream flush()但不关闭()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆