Check input redirection in CPP program

We know how REDIRECTION unix shells behave as if the input from a file (eg: input.txt) comes from the keyboard.

So I am making a cpp program that can take input via CIN either with the keyboard or with a text file using redirection

eg: ./ a.out <input.txt

But how can I check in a C ++ program if the input entered was from a file or typed from the keyboard?

+3


source to share


1 answer


This will tell you if stdin is a terminal:

isatty(STDIN_FILENO)

      



http://linux.die.net/man/3/isatty

+4


source







All Articles