When must the output stream in C++ be flushed?

后端 未结 6 1092
执笔经年
执笔经年 2021-01-21 21:45

I understand cout << \'\\n\' is preferred over cout << endl; but cout << \'\\n\' doesn\'t flush the output stream. When

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 22:24

    Flushing forces an output stream to write any buffered characters. Read streamed input/output.

    It depends on your application, in real-time or interactive applications you need to flush them immediately but in many cases you can wait until closing the file and leave the program to flush it automatically.

提交回复
热议问题