更新时间:2023-11-17 23:48:16
所以如果没有写入,文件结尾(EOF)不会自动返回?
so if there is NOTHING written, End of File, (EOF) is not returned automatically?
不,不是.它应该由用户发送.
No, it's not. It should be sent by the user.
那么是不是只有用户才能通过Ctrl+Z在stdin
中调用EOF
?
So is it that only the user can invoke
EOF
instdin
by pressing Ctrl+Z?
是的,您可以使用可以在控制台中输入的特殊组合键为 stdin
设置 EOF
指示器,对于 linux 控制台,即 Ctrl+D 对于 Windows,它是 Ctrl+Z.
Yes, you can set the EOF
indicator for stdin
with a special key combination you can input in the console, for linux console that is Ctrl+D and for windows it's Ctrl+Z.
如果是这样,那么 EOF
在 stdin
中有哪些用途?我猜它告诉程序继续阅读,直到用户调用文件结尾?是这个吗?
If so then what are some of the uses of
EOF
instdin
? I guess it tells the program to continue reading until the user user invokes end of file? is this it?
它的使用取决于你是否指示用户显式输入 EOF
,例如,我认为 python
控制台会告诉你类似 按 Ctrl+D 或输入 quit() 退出
.
The use of it depends on whether you instruct the user to input the EOF
explicitly or not, for example, I think python
console will tell you something like Press Ctrl+D or type quit() to exit
.
而 EOF
不一定是 -1
它是一个宏,您应该始终使用它来测试 EOF
指标.更重要的是 EOF
不是一个字符,它是一个特殊的值,表示 End Of F文件指示器已设置.
And EOF
is not necessarily -1
it's a macro and you should always use it to test for the EOF
indicator. And more importantly EOF
is not a character, it's a special value that indicates that the End Of File indicator is set.
另外,getchar()
等价于 fgetc(stdin)
.