Ifstream - Reset EOF Bit

I work with ifstream . I read until the EOF bit is set (I need it that way).

Why then this does not work:

 // 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 does not work at any time. I am trying to use IN.setstate(ifstream::goodbit) instead of IN.clear() too. But this is the same, am I right?

+7
source share
1 answer

Change your code as follows:

 IN.clear(); IN.seekg(0, ios::beg); 
+7
source

All Articles