For a C++ application, how can I programmatically force an end of file (EOF) on stdin?
In Windows, Control+Z is the typical keyboard shortcut to mean "end of file", in Linux and Unix it's typically Control+D .
This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended. Similarly, in bash, the EOF operator is used to specify the end of the file.
The End of the File (EOF) indicates the end of input. After we enter the text, if we press ctrl+Z, the text terminates i.e. it indicates the file reached end nothing to read.
If you're at a terminal in a Unix-like system, hit Ctrl-D
. In Windows, Ctrl-Z
.
Edit: Having seen the desire to do this "programmatically," I suggest trying fclose(stdin)
. If somehow that's not good enough, a crazier idea might be to use std::cin.rdbuf()
to set the stream to refer to something other than the true stdin, and then do what you want to that stream. But this starts to smell bad, like you are fighting against the computer, so I'd like to know more about what the real goal is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With