问题描述
我在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()但不关闭()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!