在OJ/Project中,可能会遭遇“读取直到无输出为止”的要求。
C++中,cin提供了输入停止符eof(endof file)用以标记输入结束。
对应键盘输入时,Windows下的ctrl+z回车,和Linux下的ctrl+d回车。我们可以用对应按键进行调试。
应用场景案例:
要求“you must continue reading lines until there is no more input.”
使用案例:
while(!cin.eof()){
//code
}
When coding in OJ or practical practice, we might face up with somerequirement like "reading until no input".in C++, cin provides a function eof (stands for end offile) to notify the end of the input, which corresponding to"Crtl+Z" and enter in Windows or "Ctrl+D" and enter inLinux from keyboard input. We can use these hotkeys for debugging.
Senerio case:Require that "you must continue reading lines until there is no moreinput."
Using Example
while(!cin.eof()){
//code
}