I am really confused about End of File. Suppose I am running an infinite loop. And in this loop I am taking an integer as input and then processing it, until I find an End of File. But do I check whether the input is an End of File or not. And how do I break the loop?
I use Windows, so for EOF I am typing CTRL+Z.
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
int n;
while(true)
{
cin >> n;
if(n==EOF)break;
cout << n << endl;
}
return 0;
}
When I run this code and I type CTRL+z, it prints only the last input I have given, endlessly.