标准输入流的文件(EOF)结束(标准输入) [英] End of File(EOF) of Standard input stream (stdin)

查看:1162
本文介绍了标准输入流的文件(EOF)结束(标准输入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准输入是否有任何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 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.

据OP问了一个问题:

也是如此就意味着标准输入没有EOF,我们必须手动插入它们使用Ctrl + Z或按Ctrl + D?

So does it means that stdin don't have EOF and we have to insert them manually using Ctrl+Z or 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 Ctrl+D or Ctrl+Z.

这篇关于标准输入流的文件(EOF)结束(标准输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆