The consequences and pros/cons of flushing the stream in c++

后端 未结 5 1795
心在旅途
心在旅途 2021-01-01 11:16

I have recently read an article which stated that using \\n is preferable to using std::endl because endl also flushes the stream.

5条回答
  •  滥情空心
    2021-01-01 11:32

    It is preferable to flush the buffer if you need the target of your stream to receive the data before the stream is closed.

    A real-life example would be an application log, written from a stream that's always open... You may want to look at this log while the program is still running.

提交回复
热议问题