I want to make sure data is flushed to disk when I call flush.
A simple code example is:
int main() { std::ofstream outfile("test.txt"); for (int n = 0; n < 100; ++n) { outfile << n; outfile.flush(); // TODO: insert code to make sure data is flushed to disk // I tried using the stat file size but it does not always grow after flush. } outfile.close(); return 0; } I am sure that std::ofstream properly implements the flush function. In fact I am trying test the flush function of another library and this is just an example.
flushfunction only flushes the streams buffer. There might be underlying buffers (for example in the operating system or filesystem drivers, or even on the drive itself) that might need to be flushed and synchronized. For this you need to consult the documentation for your operating system.flushat all ? I wouldnt want to flush the file inside the loopflush. Not intended to be used in practice.