“empty line received or end of the input stream” 的意思是什么?

huangapple go评论85阅读模式
英文:

What do "empty line received or end of the input stream" mean?

问题

我有一个在JVM语言上实现的直接(除了问题外)任务。
这是一个简单的命令行程序,它期望用户输入一些内容,并将结果输出到控制台。

让我困惑的部分是以下这句话:“STD输入:当接收到空行或达到输入流的末尾时,输入结束”。

关于“接收到空行”部分,我理解为用户从控制台启动了程序,程序期望用户手动输入数据,并在末尾输入空行:

$ java Main.class
输入您的数据:
数据1
数据2

结果:
结果1
结果2

在用户提交空行后,程序将关闭控制台阅读器,处理数据并将结果打印到控制台。
如果我理解有误,请纠正我。

然而,“达到输入流的末尾”这部分对我来说更加模糊。这让我想到程序接受整个输入流作为参数。
在Java中,可能会是这样:

java Main.class file.txt

这是真正意味着的吗?

从测试我的提交代码的角度来看,这更有意义。验证正确性的人将会针对许多文本文件来执行我的类,并读取程序的输出。

如果是这样,人们如何自动化地读取和验证程序的控制台输出呢?

输入在接收到空行或达到输入流末尾时结束”这句话可能意味着什么?我是否应该同时考虑用户手动输入数据和文件输入流的情况?

英文:

I have a straight forward (except the question) task to be implemented on JVM language.
This is a simple command line program which expects some input from user and outputs result to console.

The confusing part to me is the following sentence "STD input: input ends when an empty line is received or you reach the end of the input stream".

The part with empty line is received I understood as user started the program from console and the program expects the user to enter the data by hand and empty line at the end:

$ java Main.class
Enter your data:
data1
data2

Result:
result1
result2

The program closes the console reader after user submitted empty line, processes data and prints the result to the console.
Please correct me if I'm wrong.

Although, the you reach the end of the input stream part is more vague to me. This makes me think that the program takes a whole input stream as argument.
In java it might look like this:

java Main.class file.txt

Is this what it really means?

This would make more sense in terms of testing my submitted code. The person who validates the correctness will execute my class against bunch of text classes and read the output of my program.

And again, if so, how would people automate the reading validation of the console output from a program?

What does the phrase "input ends when an empty line is received or you reach the end of the input stream" might mean? Should I cover both cases when user inputs data by hand and the case with file input stream?

答案1

得分: 2

@NomadMaker在评论中提到的,输入可以通过管道传递。查看这篇文章以获取更多详细信息。

英文:

As @NomadMaker said in the comments, input can be piped. Check out this article for more details on this.

huangapple
  • 本文由 发表于 2020年8月28日 08:55:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63626001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定