Changing std::endl to put out CR+LF instead of LF

后端 未结 5 2164
忘了有多久
忘了有多久 2021-02-08 14:09

I\'m writing a program on a Linux platform that is generating text files that will be viewed on, inevitably, a Windows platform.

Right now, passing std::endl

5条回答
  •  情书的邮戳
    2021-02-08 14:58

    You shouldn't use \r\n. Just use \n, but then open the stream in "text" mode, which than will do the conversion for you. You may not care about cross-platform, but this is the official way of doing it.

    That way, the same code will spit-out \n on unix, \r\n on windows, and \r on mac.

提交回复
热议问题