#include <iostream>
using namespace std;
int main( int argc, char *argv[])
{
cout << "Hello\nWorld";
}
D:\test>hw |od -c
0000000 H e l l o \r \n W o r l d
0000014
Why additional \r is injected in windows(doesn’t happen on linux) ?
It is a feature of Windows going back to the first days of MS-DOS. In those systems, the convention is that a line delimiter is the character pair “
\r\n“. Of course, in Linux/Unix/Solaris/etc., the line delimiter is the single character “\n“There are various utilities, such as Linux’s
dos2unixandunix2doswhich do nothing but this transformation. Virtually every file transfer program has a means of dealing with it too. Seekermit‘s mode command.The convention affected the MSDOS/windows
Cruntime library functionfopen()(among others): the second parameter can have abortto explicitly set the line delimiter conversion. Atext conversion transforms\r\nto\non input and\nto\r\non output. Abinary conversion does no such transformation.