Good question!
For IOIs you will always know when the input is finished.
Also on stdin you will have EOF.
Try it by writing your own program, and then do
program < input.txt
You'll see that you can find stein for your input.txt
If you're typing things manually you can use CTRL-D to send EOF.