End of File(EOF) of Standard input stream (stdin)

Speaking about EOF in stdin: when you redirect input from file, e.g.:

program <input.txt

the file already has an EOF, so this is not a problem. In console you can simulate EOF flag. In UNIX systems it is Ctrl+D, in Windows Ctrl+Z. When you type this in the console, program will behave like it has just reached end of input file.


Edit

According to a question asked by OP:

So does it means that stdin don’t have EOF and we have to insert them manually using Ctrl+Z or Ctrl+D?

Actually — yes. One may consider stdin (not redirected, but taken from the console) as infinite file — no one can tell where does it end. The end of input file, where input ist stdin, must be told literally by Ctrl+D or Ctrl+Z.

Leave a Comment