c newline character under windows command line redirection

This isn't particular to command-line redirection or stdout, the same would be true with any file descriptor open in character mode (as opposed to binary mode).

If you've ever written a C++ program on Windows that generates text output (e.g., logs, configuration files, or data exports), you may have noticed an annoying quirk: by default, newline characters (\n) are converted to CR+LF (Carriage Return + Line Feed, \r\n) instead of the Linux/Unix-style LF ( Line Feed, \n). This can cause issues when the output is shared with Linux systems, where CR+LF ...
Key Details About Windows C Plus Plus Newline Character Under Windows Command Line Redirection

Yes yes, I am aware that '\n' writes a newline in UNIX while for Windows there is the two character sequence: '\r\n'. All this is very nice in theory, but my question is why? Why the carriage return character is extra in Windows ? If UNIX can do it in \n why does it take Windows two characters to do this? I am reading David Beazley's Python book and he says: For example, on Windows , writing the ...
You may have noticed that Windows has a different way of storing newlines than Mac and Linux. A newline on Windows is encoded as \r\n, which symbolizes a Carriage Return (CR) followed by a Line Feed (LF). By contrast, Mac and Linux simply use a \n. Why does Windows do its own thing, and why does it use two characters to signal the start of a new line ?

Carriage Return (CR) vs Line Feed (LF)
While using text files in scripts on different operating systems, you may be concerned with different newline characters , which can also lead to confusion and file incompatibility. Two primary characters are used to denote the end of a line : Carriage Return (CR) and another command called Line Feed (LF). This article will explain their History, Usage in Different Operating Systems, Related ...
Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character , single quotation mark, or certain other characters in a character constant, you must use escape sequences.

C New Lines
The newline character (\n) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line .





