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

前端 未结 2 1739
孤街浪徒
孤街浪徒 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

    If using Linux (and probably other unixes, but definitely not Windows) you could try isatty.

    There's no direct way of extracting the file descriptor from the C++ stream. However, since in a C++ program both cout as well as stdout exist and work at the same time (C++ by default provides synchronisation between stdio and iostream methods), your best bet in my opinion is to do a isatty(fileno(stdout)).

    Make sure you #include .

提交回复
热议问题