Get platform specific end of line character in C++/Qt

后端 未结 4 1577
孤城傲影
孤城傲影 2021-01-18 17:27

Is there anything for getting right end-of-line symbol for any platform? I mean, I can use \\n for Windows and Unix if I want to write EOL to file, but there is

4条回答
  •  半阙折子戏
    2021-01-18 17:56

    When you are writing a file in text mode, the "\n" character should be reinterpreted as whatever is appropriate for that system. For Windows, that means CRLF (carriage return, line feed), on Unix, it's just LF alone, and the Macintosh standard is a CR by itself.

    When you are reading, be ready to end a line at either one of those characters, but if you find a carriage return, check to see if there is a line feed immediately after it, and if there is, consider it part of the same line.

提交回复
热议问题