What is the use of * both * Carriage return and linear channels?

I would think that is enough. But what to do CRLF ( 0x0D0A ) when you can just use CR ( 0D )? Usually when I use strings (C ++), I do this:

 myString = "Test\nThis should be a new line!\nAnother linefeed."; 

NOTE. For non-C ++ programmers who read this, "\n" is the line feed ( 0x0A ).

But I really have to do this:

 myString = "Test\r\nThis should be a new line!\r\nAnother carriage return/linefeed pair."; 

NOTE: "\r" means carriage return ( 0x0D ).


EDIT: Should it be on Programmers.SE?

+4
source share
4 answers

Remember that all these codes came from old Teletype machines. These were actually typewriters: it was necessary both to advance the paper along the line (s) and to return the print head (on the carriage) to the left side of the paper (carriage return).

+14
source

On Windows / Unix / old Mac systems, each way of writing newlines to text files (rather than binary). If you program under windows, then in binary mode you will read (and you probably want to write) CRLF endings. On unix-like systems, this will be just LF.

If you are dealing with your own data formats ... it doesn't matter which option you choose. It all depends on what you want to do with the string and where you got it from.

+1
source

Some systems, such as UNIX and OSX, simply use a translation line, DOS uses optional carriage returns to be compatible with teletypes, and Windows inherited the architecture.

+1
source

You use both on Windows because it is custom on Windows. It is so simple. But you only write files designed for Windows.

0
source

Source: https://habr.com/ru/post/1337400/


All Articles