Understanding the need for fflush() and problems associated with it

后端 未结 3 407
遇见更好的自我
遇见更好的自我 2020-12-07 22:09

Below is sample code for using fflush():

#include 
#include 
#include 
#include 

void flush(FILE *         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 22:38

    fflush() empties the buffers related to the stream. if you e.g. let a user input some data in a very shot timespan (milliseconds) and write some stuff into a file, the writing and reading buffers may have some "reststuff" remaining in themselves. you call fflush() then to empty all the buffers and force standard outputs to be sure the next input you get is what the user pressed then.

    reference: http://www.cplusplus.com/reference/cstdio/fflush/

提交回复
热议问题