how to check the end of a txt file??
???Code:if(file.eof()){.....}
thank you for helping~~~
how to check the end of a txt file??
???Code:if(file.eof()){.....}
thank you for helping~~~
oh.......that's correct, but how to move back to the begin of file???
Favorite Quote:
>For that reason someone invented C++.
BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!
well error found cos i think i open the file using
is there any other method?Code:ifstream file(.......)
seekg!
Favorite Quote:
>For that reason someone invented C++.
BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!
thank you ... i have use the seekg function and i have also use tellg and it said that the position is zero.
but when i use getline to get the character, the character is empty.
what is the problem??
out put:Code:if(file7.eof()) { cout << "eof" << endl; cout << file7.tellg() << endl; file7.seekg(0); file7.getline(RFQ,14); cout << "||" << RFQ << "||" <<endl; file7.seekg(0); cout << file7.tellg() << endl; } if (file7.eof()) { cout << "again!!!" << endl; }
eof
0
||||
0
again!!
Code:if(file7.eof()) { cout << "eof" << endl; cout << file7.tellg() << endl; file7.seekg(0); Here you could try adding a clear(): file7.clear();
instead of
file7.seekg(0);
you could try
file.seekg(0, ios::beg)
to explicitly indicate you want to go back to beginning of file.
Are you sure there is anything in the file?