I'm working with ifstream
. I read until EOF bit is set (I need this way).
Why then don't work this:
// IN is ifstream file. CH is char.
if (IN.eof()) {
IN.seekg(ios::beg);
IN.clear();
if (read((char*)&CH, sizeof(CH)))
cout << "Succes.";
else
cout << "Not S.";
}
The read
function isn't success anytime. I try use IN.setstate(ifstream::goodbit)
instead IN.clear()
too. But it is the same, am I right?
Change your code like this:
IN.clear();
IN.seekg(0, ios::beg);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With