关闭 fstream 是否保证与文件系统同步?我正在与同事讨论这个问题,需要一个明确的引用。我对标准的内容以及 Visual Studio 实现在 Windows 上发生的情况很感兴趣。
此外,如果关闭并不意味着同步,是否有标准的 C++ 方法来确保同步完成?
最佳答案
我很确定它已经解决了关闭文件流如何关闭缓冲区。所以,现在,缓冲区:
draft of Std'1998 : 27.8.1.3.6: basic_filebuf* close();
6 Effects: If is_open() == false, returns a null pointer. If a put area exists, calls overflow(EOF) to flush characters. (...) Finally it closes the file (‘‘as if’’ by calling std::fclose(file)).308) If any of the calls to overflow or std::fclose fails then close fails.
现在,查看 overflow()
:27.8.1.4.8 (...)
然后我试图进一步追踪它,在某处有一些对 sync
和 sputc
的引用,但我无法追踪到如何使用的确切措辞 overflow
保证刷新。确实如此,但抱歉,我今天的时间到了:/
关于c++ - 关闭 fstream 是否保证文件系统同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19513203/