Original: http://hane00.blog.163.com/blog/static/1600615220126204446809/
' \ R ' is a carriage return, ' \ n ' is a newline, the former causes the cursor to start at the beginning of the line, which causes the cursor to move down one grid. The usual enter is two to add together. Turn to an article below.
Carriage return and line break
Today, I finally figured out the origins and differences between the "carriage return" (carriage return) and the "line feed" concept.
Before the computer appeared, there was a gadget called a telex typewriter (teletype Model 33) that could play 10 characters per second. But it has a problem, that is, when the line is finished, it will take 0.2 seconds to hit two characters. If there are new characters coming in this 0.2 seconds, then this character will be lost.
So, the developers think of a way to solve this problem, is to add two after each line to end the character. One is called "carriage return", which tells the typewriter to position the printhead at the left border, and the other is called "line break", telling the typewriter to move the paper down one line.
This is the origin of "line break" and "carriage return", from their English name can also be seen in one or two.
Later, the computer invented, these two concepts are also like to the computer. At that time, memory was expensive, and some scientists thought it would be too wasteful to add two characters at the end of each line. So, there was a disagreement.
Unix system, each line at the end of only "< line >", that is, "\ n", the Windows system, the end of each line is "< newline >< Enter >", that is "\ r \ n", the Mac system, the end of each line is "< Enter >". A direct consequence of this is that if the file under the Unix/mac system is opened in Windows, all the text will be turned into one line, and if the files in Windows are opened under Unix/mac, a ^m symbol may appear at the end of each line.
C Language Programming (Windows system) \ r is return to the beginning of the line of the bank this will overwrite the previous output
Such as:
int main () {
cout << "hahaha" << "\ r" << "Xixi";
}
Finally, only Xixi is shown and hahaha is covered.
\ n is the carriage return + line break move the cursor first to the beginning and then to the next line, which is the beginning of the next line.
int main () {
cout << "hahaha" << "\ n" << "Xixi";
}
The display
hahaha
A summary of their own.
/t equivalent to the Keyboard tab,/N line new Line,/r carriage return Carriage REturn, the basic concept should be a carriage return to the front, the newline represents a line break.
Different operating systems, line Fu Cao are also different:
/R Mac
/n Unix/linux
/r/n Windows
[Java]View Plaincopy
- /**
- * Get line break for current system
- */
- ublic static void LineSeparator () {
- Note When you write a stream to a file, the line break should vary depending on the operating system.
- In the program we should try to use System.getproperty ("Line.separator") to obtain the current system of exchange
- Line character, not write/r/n or/n.
- It's not flexible enough to write a program
- When we output in the Java console, the/R and/n can all achieve the effect of line wrapping.
- if (System.getproperty ("Line.separator"). Equals ("/r/n")) {
- System.out.println ("//r//n is for Windows");
- } else if (System.getproperty ("Line.separator"). Equals ("R")) {
- System.out.println ("//R is for Mac");
- } else if (System.getproperty ("Line.separator"). Equals ("/n")) {
- System.out.println ("//n is for Unix/linux");
- }
- System.out.println ("Aa/nbb");
- System.out.println ("Aa/rbb");
- System.out.println ("AA/TBB");
Go Carriage return line break in Java/N/R/t