how to use isatty() on cout, or can I assume that cout == file descriptor 1?

前端 未结 2 1740
孤街浪徒
孤街浪徒 2020-12-07 01:56

Well, the subject says it all, basically.

I have a command-line utility that may be used interactively or in scripts, using pipes or i/o redirection. I am using

2条回答
  •  一生所求
    2020-12-07 02:57

    It is possible to use rdbuf() to change the destination of std::cin and std::cout inside your program. If you don't do that, it is probably quite safe to assume that cin = 0, cout=1 and clog and cerr both = 2 as the C++ standard states that they are synchronized with C stdin, stdout and stderr and those have per POSIX those file descriptors at startup.

提交回复
热议问题