what does std::endl represent exactly on each platform?

后端 未结 5 1309
孤独总比滥情好
孤独总比滥情好 2021-01-11 12:01

Thinking about UNIX, Windows and Mac and an output stream (both binary and text),

What does std::endl represent, i.e. ,

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-11 13:02

    Quoted from the accepted answer on a related question:

    The varying line-ending characters don't matter, assuming the file is open in text mode, which is what you get unless you ask for binary. The compiled program will write out the correct thing for the system compiled for.

    The only difference is that std::endl flushes the output buffer, and '\n' doesn't. If you don't want the buffer flushed frequently, use '\n'. If you do (for example, if you want to get all the output, and the program is unstable), use std::endl

    In your case, since you specifically want , you should explicitly use \r\n, and then call std::flush() if you still want to flush the output buffer.

提交回复
热议问题