I have the txt file which contains for example:
Arthur 20
Mark 21
Josh 12
The are no empty lanes between, its only for readability!
What I want to do is write it on the screen in the same way as it is in the file.
I tried to make it this way:
ifstream file;
string word;
file.open("data.txt");
while(!file.eof()){
file >> word;
if(file.fail())
break;
cout << word << " ";
file >> word;
cout << word << endl;
}
But the output is:
Arthur 20
Mark 21
Josh 12
0
So why this 0 is being caught as a empty line to my string variable? I thought that fail() should stop the loop and leave me with correct output?