In standard C++, you can't. However on Posix systems you can using isatty:
#include
#include
int const fd_stdin = 0;
int const fd_stdout = 1;
int const fd_stderr = 2;
int main()
{
if (isatty(fd_stdin))
std::cout << "Standard input was not redirected\n";
else
std::cout << "Standard input was redirected\n";
return 0;
}