c++filefseek

Will fseek function flush data in the buffer in C++?


We know that calls to functions like fprintf or fwrite will not write data to the disk immediately; instead, the data will be buffered until a threshold is reached. My question is: if I call the fseek function, will these buffered data be written to disk before seeking to the new position? Or is the data still in the buffer, and is written to the new position?


Solution

  • I'm not aware if the buffer is guaranteed to be flushed, it may not if you seek to a position close enough. However there is no way that the buffered data will be written to the new position. The buffering is just an optimization, and as such it has to be transparent.