On a POSIX system you can test if stdin, i.e. fd 0 is a TTY:
#include <unistd.h>
is_redirected() {
return !isatty(0) || !isatty(1) || !isatty(2);
}
is_input_redirected() {
return !isatty(0);
}
is_output_redirected() {
return !isatty(1) || !isatty(2);
}
is_stdout_redirected() {
return !isatty(1);
}
is_stderr_redirected() {
return !isatty(2);
}
This is not part of the C++ standard library, but if running on a POSIX system part of the evailable ecosystem your program is going to live in. Feel free to use it.