Http://blog.chinaunix.net/uid-12706763-id-10830.html
Different OS have different newline characters:
OS |
Line break |
Kanji Code |
Unix |
LF |
JIS, EUC, (ShiftJIS) |
Windows |
Cr+lf |
ShiftJIS |
Macintosh |
CR |
ShiftJIS |
The transformation relationships between the various systems are listed below:
UNIX = Windows
% Perl-pe ' s/\n/\r\n/' unixfile > Winfile
UNIX = Macintosh
% Perl-pe ' s/\n/\r/' unixfile > macfile
Win = Unix
% Perl-pe ' s/\r\n/\n/' winfile > Unixfile
Windows =& Gt Macintosh
% Perl-pe ' s/\r\n/\r/' winfile > macfile
Macintosh = > Unix
% Perl-pe ' s/\r/\n/g ' macfile > Unixfile
Macintosh = Windows
% Perl-pe ' s/\r/\r\n/g ' macfile > Winfile
In text processing, CR, LF, cr/lf are line breaks used on different operating systems.
DOS and Windows use carriage return + newline cr/lf to represent the next line,
Unix/linux uses the newline character LF to indicate the next line,
The Mac OS system uses a carriage return CR to represent the next line.
The CR symbol ' \ r ' indicates that the decimal ASCII code is 13 and the hexadecimal code is 0x0d;
LF using the ' \ n ' notation, the ASCII code is 10, and the 16 system is 0x0a.
So the line breaks in the Windows platform are represented in a text file using 0d 0a two bytes, while the line breaks on UNIX and Apple platforms are expressed in 0a or 0d of a byte.
The runtime on the general operating system automatically determines the line-wrapping format of the text file. A program that runs on Windows generates a text file in a cr/lf format, while running on Linux generates a text file that is wrapped in the LF format.
A file file that uses another line break on one platform can cause unexpected problems, especially when editing program code. Sometimes the code appears normal in the editor, but when you edit it, the error occurs because of a line break.
Many text/code editors have a newline character conversion feature that allows you to swap line breaks in text files in different formats.
When transferring files between different platforms using FTP software, in ASCII text mode transfer mode, some FTP client programs automatically convert to the line format. The number of file bytes passed through this transfer may vary. If you do not want FTP to modify the original file, you can use bin mode (binary mode) to transfer the text.
C + + about line break