Given the following code:
int main(){
ifstream ins;
ins.open("infile.txt");
int i = 0;
int x = 0;
while (ins) {
ins >> x;
cout << i;
i++;
}
ins.close();
}
Assume infile.txt contains:
1 2 3
What's the difference between the current while loop condition, and if the while loop condition is "ins.good()" instead?
I assumed they were the same thing until I inputted it to my IDE, where the code outputted 0123 when I passed ins, and 012 when passing ins.good().
I've been trying to figure this out for a while, but got nowhere.
Thank you so much!