What is the difference between “\\r” and “\\n”? [duplicate]

淺唱寂寞╮ 提交于 2019-12-06 14:11:16

Because it just isn't.

\r means "carriage return". \n means "new line" line feed

Some systems are wise enough to suggest that all they need to get the cursor to a new line is \n. Others think that it's more appropriate to go \r\n, because, they may claim that the column position needs to be reset as well (i.e. the \r).

Sometimes in computing things are 'just this way'. This is one of those cases :)

The difference between '\r' and '\n' is 3.

The accepted answer isn't exactly accurate. In point of fact, \n means 'linefeed', not 'new line'. The distinction is important because both symbols hearken back to the days of teletypes as the primary output for a computer instead of a CRT or LCD. For a teletype, the act of moving the print head back to column 1 and the act of feeding the paper up 1 line were two distinct actions. As to the origin of the differing conventions for end of line characters in files, the other answers have correctly pointed out that this is just a historical curiosity.

it isn't consistent due to the historical decisions made by each operating system maker. as for the differences, see characters 12 and 15 here: http://www.asciitable.com/

Some systems don't even have the concept of an end of line. VAX/VMS and the IBM VM operating systems all support record-based files where no end of line marker is needed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!