Question

I have a c++ driver that contains a do-while loop. Inside this loop, I have data written to disk every so many iterations by a member function of a class. The funny thing is, the function seems to write almost all of the data for the nth time it is called, but then write the rest the (n+1)th time. It then proceeds to write some of the (n+1)th data and stops writing pre-maturely, etc...

Forgive me for possibly speaking imprecisely here, but I suspect that the filestream is storing the data and does not have enough time to finish writing it to disk (there is a lot of data to write each time the function is called). It then writes what was left over from the last time it was used and tries to move on to what it was supposed to currently be doing.

Has anyone encountered a similar problem? Is there a way to keep a program from moving on before a fstream is completely done writing?

Was it helpful?

Solution

You can call fstream::flush() to ensure that the stream is synchronized with the underlying storage device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top