Differences between "\ n" and "\ r" in the code

Source: Internet
Author: User
'\ 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.

Carriage Return and line feed
In Unix systems, each line ends with "<line feed>", that is, "\ n". In Windows systems, each line ends with "<line feed> <press enter> ", 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 be changed to a line; if a file in Windows is opened in UNIX/MAC, A ^ m symbol may be added at the end of each line.

In C language programming (Windows System), \ r means 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

Differences between "\ n" and "\ r" in the code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.