I'd like some information, stored in a buffer, to be written to the file, when I call close() on the file.
I have looked at FileBuf and pubsetbuf, among others. However, after testing, they are not buffering it (the way I expect them to).
How can I achieve the same as BufferedOutputStream(Java) in C++?
fprintf writes are buffered, but the OS may flush the buffer when deemed convenient. Writes to stderr are an exception and are not buffered.
If this bothers you, I suggest creating a secondary buffer, which you then write to the file and fflush().
What exactly is the behaviour you are/are not seeing? Are individual characters being written to the file with every write?
Last edited on