问题描述
标准输入是否有任何EOF?对于例如 - 如果我开始使用的fread从标准输入读/写那么当下面的循环将结束
Does stdin has any EOF? For e.g - If i start reading from stdin using fread/read then when the following loop will end?
while ((c = read(0, buffer, BUFSIZ)) > 0) {
.
.
.
}
如果上述解决方案是否定的,那么有没有什么办法可以在标准输入添加EOF?
If the solution of above is no, then is there any way to add EOF in the stdin?
推荐答案
在标准输入谈到 EOF
:当您从文件重定向输入,例如:
Speaking about EOF
in stdin: when you redirect input from file, e.g.:
program <input.txt
该文件已经有一个 EOF
,所以这不是一个问题。在控制台中,您可以模拟 EOF
标记。在UNIX系统中,控制 + D ,在Windows 控制 + 以Z 。当您在控制台中输入这个,程序会像它刚刚达到输入文件的末尾。
the file already has an EOF
, so this is not a problem. In console you can simulate EOF
flag. In UNIX systems it is +, in Windows +. When you type this in the console, program will behave like it has just reached end of input file.
据OP问了一个问题:
也是如此就意味着标准输入没有EOF,我们必须手动插入它们使用Ctrl + Z或按Ctrl + D?
其实 - 是的。可以考虑标准输入(未进行重定向,而是从控制台获取)为无限的文件 - 没有人能告诉它在哪里结束。输入文件,其中输入IST标准输入结束后,必须由控制 + D 或控制 + 以Z 。
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 + or +.
这篇关于标准输入流的文件(EOF)结束(标准输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!