Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ifstream - Reset EOF bit

Tags:

c++

eof

ifstream

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?

like image 572
Nanik Avatar asked Mar 11 '12 14:03

Nanik


1 Answers

Change your code like this:

IN.clear();
IN.seekg(0, ios::beg);
like image 98
Raphael Bossek Avatar answered Oct 14 '22 12:10

Raphael Bossek