how to check the end of a txt file??
???Code:if(file.eof()){.....}
thank you for helping~~~
This is a discussion on how to check the end of file? within the C++ Programming forums, part of the General Programming Boards category; 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???
"A government big enough to give you everything you want, is big enough to take away everything you have." - Thomas Jefferson
MSVS 2008 Pro / DevPartner / CB NightlyBuilds / MinGW / Cygwin
well error found cos i think i open the file using
is there any other method?Code:ifstream file(.......)
seekg!
"A government big enough to give you everything you want, is big enough to take away everything you have." - Thomas Jefferson
MSVS 2008 Pro / DevPartner / CB NightlyBuilds / MinGW / Cygwin
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?