how C output LF to stdout without being changed to CR LF?

前端 未结 3 710
后悔当初
后悔当初 2020-12-11 05:15

On Windows this

#include 

int main() { 
    putc(\'A\',stdout);
    putc(\'\\r\',stdout); 
    putc(\'\\n\',stdout);
}

outp

3条回答
  •  执笔经年
    2020-12-11 05:46

    The MSVC solution is:

    #include 
    #include 
    ...
    _setmode(1,_O_BINARY)
    

    Other runtimes may provide the C99 solution or an alternate way. EDIT: I believe setmode([file number],O_BINARY) originated on Borland Turbo C, and other compilers for MS-DOS and Windows imitated it. The _ prefix is done to keep the namespace clean, and may not be present on some compilers.

提交回复
热议问题