How come infile.eof() is never true in this example? I am stuck in an infinite loop... but I know that the size of input.txt is only 100bytes.
Code:ifstream infile("input.txt", ios::in); while (!infile.eof()) { infile.seekg(1, ios::cur); }
How come infile.eof() is never true in this example? I am stuck in an infinite loop... but I know that the size of input.txt is only 100bytes.
Code:ifstream infile("input.txt", ios::in); while (!infile.eof()) { infile.seekg(1, ios::cur); }
You can try putting in a call to tellg in the loop and see if/how the get pointer is moving. If it keeps giving you the same value back, something is wrong.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
No, I put in a cout << tellg() and that keeps increasing by one, but it never stops.. why?
You can move the file pointer all you like, but if you never attempt to read from the file, eof will never get set.