While reading this question, I found in the answers different way of reading an integer. Here are two of them.
The one from πάντα ῥεῖ's answer:
if(iFile) {
iFile >> int1;
cout << "From first file:" << int1 << endl;
}
The one from JRowan's answer:
if(!iFile.eof()){
iFile >> int1;
cout << "From first file:" << int1 << endl;
}
But I was wondering if using the code below is equivalent to the two above? Also, is there any reason not to use one of the three sample codes?
if (iFile >> int1) {
cout << "From first file:" << int1 << endl;
}
Thanks.