In simple terms, what is the purpose of flush() in ostream

后端 未结 2 1124
余生分开走
余生分开走 2021-01-05 22:40

By definition taken from: http://www.cplusplus.com/reference/iostream/ostream/flush/ , it is not clear why the function exists, and for what purpose you would use it for. Wh

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-05 23:27

    Writing file on hard-drive one character per time is inefficient. Sending a packet over network for each character is inefficient. Therefore streaming is often cached. flush() is just a way to control "manually" during streaming when the cache must be flushed and the stuff should be really sent or written.

提交回复
热议问题