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

Well, the subject says it all basically.

I have a command line utility that can be used interactively or in scripts using pipes or I / O redirection. I use cinit coutfor i / o, and I want to write an additional EOL at the end if the output is console, so the user request will start on the next line. Inside the scripts this would be harmful.

Can it be considered cin == 0, cout == 1? I understand that there is no clean way to get a file descriptor for a stream. Or that?

+5
source share
2 answers

rdbuf() std:: cin std:: cout . , , cin = 0, cout = 1 clog cerr both = 2, ++ , C stdin, stdout stderr, , POSIX .

+6

Linux (, , unixes, Windows), isatty.

++. , ++- cout, stdout (++ stdio iostream), , , isatty(fileno(stdout)).

, #include <unistd.h>.

+13

All Articles