问题
Possible Duplicate:
What is the difference between \r and \n?
I understand that it's different for each operating System, for example, "\r\n" may be expected in Windows, "\n" may be expected in Unix snd "\r" may be expected in Macs.
What are the differences between these two (or three, if you want to include "\r\n") escape sequences? Why isn't it consistent across all systems?
I'm curious about this.
回答1:
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 :)
回答2:
The difference between '\r' and '\n' is 3.
回答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.
回答4:
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/
回答5:
Wikipedia is your friend :)
回答6:
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.
来源:https://stackoverflow.com/questions/1355095/what-is-the-difference-between-r-and-n