I was going through a C++ tutorial that showed how to read from a text file. In the tutorial, it's been mentioned that "while(file)" and "while(!file.eof())" is the same, where file is of ifstream type. But for some reason, I get different results(I added my results in this post). Some help will be really appreciated
int main()
{
string fileName = "read_text.txt";
ifstream inFile;
inFile.open(fileName);
if(inFile.is_open())
{
string line;
while(inFile)
{
getline(inFile, line);
cout<<line<<endl;
}
cout<<endl;
inFile.clear();
inFile.seekg(ios::beg);
while(!inFile.eof())
{
getline(inFile, line);
cout<<line<<endl;
}
inFile.close();
}
else cout<<"The file failed to open";
return 0;
}