码迷,mamicode.com
首页 > 其他好文 > 详细

New line

时间:2016-10-06 17:31:29      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

The concepts of line feed (LF) and carriage return (CR) are closely associated, and can be either considered separately or together.

https://en.wikipedia.org/wiki/Newline

What is the difference between \r and \n?

They‘re different characters. \r is carriage return, and \n is line feed.

On "old" printers, \r sent the print head back to the start of the line, and \n advanced the paper by one line. Both were therefore necessary to start printing on the next line.

Obviously that‘s somewhat irrelevant now, although depending on the console you may still be able to use \r to move to the start of the line and overwrite the existing text.

More importantly, Unix tends to use \n as a line separator; Windows tends to use \r\n as a line separator and Macs (up to OS 9) used to use \r as the line separator. (Mac OS X is Unix-y, so uses\n instead; there may be some compatibility situations where \r is used instead though.)

For more information, see the Wikipedia newline article.

EDIT: This is language-sensitive. In C# and Java, for example, \n always means Unicode U+000A, which is defined as line feed. In C and C++ the water is somewhat muddier, as the meaning is platform-specific. See comments for details.

 

技术分享

New line

标签:

原文地址:http://www.cnblogs.com/simoncook/p/5933869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!