7

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?

David G
  • 94,763
  • 41
  • 167
  • 253
Nanik
  • 603
  • 1
  • 12
  • 19

1 Answers1

7

Change your code like this:

IN.clear();
IN.seekg(0, ios::beg);
Raphael Bossek
  • 1,904
  • 14
  • 25