How to make cout behave as in binary mode?
问题 Every time I do \'cout << endl\' or even \'cout << \"\\n\"\' and then launch my program under Windows to output to a file (\"a.exe < test.in > result.out\") I get \"\\r\\n\" line endings in \"result.out\". Is there on earth a way to stop it doing so and just output \"\\n\" on every \'cout << \"\\n\"\'? Thanks in advance. 回答1: This works using Visual Studio 2013: #include <io.h> #include <fcntl.h> #include <iostream> int main( int argc, char * argv[] ) { _setmode( _fileno( stdout ), _O_BINARY