这篇直接就用英文写了,懒得用中文去想了,还得去想对应的词怎么翻译成中文。凑合着看吧。
If you are familiar with pipelining in linux using stdin and stdout, you may get frustrated if you use C lib provided by MS VC. In MS VC, stdin and stdout are opened in text mode by default. If you try to send binary data, it will get corrupted due to unrecognized "text character". The solution is to change stdin/stdout to binary mode.
Take stdin as example, here is the code:
#include <fcntl.h>
#include <io.h>
#include <iostream>
if(_setmode(_fileno(stdin), _O_BINARY) == -1)
std::cerr << "Cannot set stdin to binary mode.\n";
See the example here.