这篇直接就用英文写了,懒得用中文去想了,还得去想对应的词怎么翻译成中文。凑合着看吧。
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.

本文详细解释了在使用MSVC时,由于stdin/stdout默认为文本模式,导致无法正确传输二进制数据的问题,并提供了解决方案。通过使用_setmode函数将输入输出流设置为二进制模式,可以有效避免数据损坏,确保数据传输的准确性。
5873

被折叠的 条评论
为什么被折叠?



