如何在平台无关代码中处理eof()? C ++

时间:2017-01-26 10:22:58

标签: c++ linux pipe eof

我有一个c ++代码,我将stdout重定向到一个字符串。代码应该与平台无关。在Windows中工作正常,但在linux下它不会构建。 这是我的代码:

#include <fcntl.h>

int outBuffer[2];
int orgStdOutBuffer;
std::string stringBuff;
enum PIPES {READ, WRITE};
orgStdOutBuffer = dup(fileno(stdout));
outBuffer[READ] = 0;
outBuffer[WRITE] = 0;

if (_pipe(mStdOutBuffer, 65535, O_BINARY) == -1) {
        return false;
}
fflush(stdout);
dup2(outBuffer[WRITE], fileno(stdout));

问题出在我检查管道末端的地方:

if (!eof(outBuffer[READ])) {
    stdOutBufferSize = read(outBuffer[READ], &(*stringBuff.begin()), buffSize);
}

在linux下出现以下错误:

'eof' was not declared in this scope
'O_BINARY' was not declared in this scope

任何人都可以帮助我如何在linux下运行此代码?

0 个答案:

没有答案