"\r\n","\r","\n"

Reference: http://blog.csdn.net/xiaofei2010/article/details/8458605

 

'\r' : carriage return

'\n' : newline character

The following is the test code of the C++ language, which has nothing to do with the platform (at least under win, the effect is the same as under linux)


 The results are as follows:

Carriage return (\r): Each time the cursor moves to the beginning of the line.

Carriage return and line feed (\r\n): Each time the cursor moves to the beginning of the next line.

Line feed (\n): Move the cursor to the next line, because the next line has no content, so the effect is the same as the carriage return line feed effect

 

Two extension

       The above are the different effects of the print statement on the parsing of these two characters. They are two separate concepts from the following things. Although there is some connection between the two, do not confuse the concepts.

The origin and difference between the concepts of "Carriage Return" and "Line Feed".

Symbol ASCII code Meaning

\n 10 line feed

\r 13 Enter

Before the advent of computers, there was a thing called a teletypewriter (Teletype Model 33, from which the concept of tty under Linux/Unix came from), which could type 10 characters per second. But it has a problem, that is, it takes 0.2 seconds to finish typing a line feed, which is just enough to type two characters. If in this 0.2 seconds, a new character is passed, then this character will be lost.

Therefore, the developers thought of a way to solve this problem, which is to add two characters to indicate the end of each line. One, called "carriage return," told the typewriter to position the printhead at the left border; the other, called "line feed," told the typewriter to move the paper down one line. This is the origin of "line feed" and "carriage return", which can also be seen from their English names.

Later, the computer was invented, and these two concepts were applied to the computer. At the time, memory was expensive, and some scientists thought adding two characters at the end of each line was too wasteful, adding one was fine. So, there was a disagreement.

In Windows, each line ends with "\r\n"

On Unix systems, each line ends with "\n"

On mac systems, each line ends with "\r"

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326776038&siteId=291194637