EOF



C

In computing, end-of-file (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

EOF在Unix系统上对应的是Control-D,在Windows上是Control-Z

例如下面输入2个数字的C++程序test.cpp:

#include <iostream>

int main()
{
        int x, y;
        while ( std::cin >> x >> y )
        std::cout << '/' << x << '/' << y << "/n";
        if ( std::cin.eof() )
                std::cout << "End of inputn";
        else
                std::cout << "There was an errorn";
}

在输入两个字符5 6之后,打印出/5/6/,然后在键入ctrl-DEOF,程序输出"End of input",否则输出"There was an error"。

$./test
5 6
/5/6/
End of input
$./test
5 6
/5/6/
a
There was an error