how to check the end of a txt file??
???Code:if(file.eof()){.....}
thank you for helping~~~
Printable View
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???
well error found cos i think i open the file using
is there any other method?Code:ifstream file(.......)
seekg!
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?