Does Windows carriage return \r\n consist of two characters or one character?
Solution 1:
These are two characters:
-
\r
is carriage return; -
\n
is line feed.
Two characters combined represent a new line on Windows. Whereas on Linux, \n
represents new line. It moves cursor to the start of new line on Linux. On Windows, the cursor will stay at the same column in the console but on the next line.
\r
on Linux has the same effect as on Windows: moves cursor to the start of the line. It is possible to print different information on the same line where \r
is used instead of \n
.
Solution 2:
Actually \r is 0x0D (^M) and \n is 0x0A (^J)
, but..... on windows:
\n will write 0x0D 0x0A
on unix:
\r will write 0x0D
\n will write 0x0A