'\ R' is the carriage return,' \ n' is the line feed, the former causes the cursor to the beginning of the line, and the latter causes the cursor to move down one cell . Generally, two keys are used together. . Next, I will refer Article .
Carriage Return and line feed
Today, I have finally figured out the origins and differences between carriage return and line feed.
Before the computer appeared, there was a kind of device called teletype model 33, which can contain 10 characters per second. But there is a problem, that is, when a line breaks a line, it takes 0.2 seconds, just two characters. If a new character is passed in the 0.2 s, the character will be lost.
As a result, the developers thought of a way to solve this problem, that is, adding two end characters after each line. One is "enter", which tells the typewriter to position the print head on the left boundary, and the other is "line feed", which tells the typewriter to move the paper down one line.
This is the source of "line feed" and "Carriage Return". They can also be seen in their English names.
Later, computers were invented, and these two concepts were invented on computers. At that time, memory was very expensive. Some scientists thought it would be too waste to add two characters at the end of each line. Just add one character. As a result, there were differences.
In Unix systems, each line ends with "<line feed>", that is, "\ n". In Windows systems, each line ends with "<line feed> <return to car> ", that is, "\ n \ r". In MAC systems, the end of each line is "<press enter> ". One direct consequence is that if a file in UNIX/MAC is opened in windows, all the text will become a line. If a file in Windows is opened in UNIX/MAC, A ^ m symbol may be added at the end of each line.
C LanguageIn programming (Windows), \ r is the return to the beginning of the line. This overwrites the previous output of this line.
For example:
Int main (){
Cout <"HAHAHA" <"\ r" <"Xixi ";
}
At last, only Xixi is displayed, and hahaha is overwritten.
\ N is the carriage return + line feed. The cursor is first moved to the beginning of the line and then switched to the next line, that is, to pull the first line of the next line.
Int main (){
Cout <"HAHAHA" <"\ n" <"Xixi ";
}
Display
Hahaha
Xixi
From: http://javaeye-mao.iteye.com/blog/211354