How does does ifstream eof() work?
<pre><code>#include &lt;vector&gt;
#include &lt;list&gt;
#include &lt;map&gt;
#include &lt;set&gt;
#include &lt;deque&gt;
#include &lt;stack&gt;
#include &lt;bitset&gt;
#include &lt;algorithm&gt;
#include &lt;functional&gt;
#include &lt;numeric&gt;
#include &lt;utility&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;cstdio&gt;
#include &lt;cmath&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;cctype&gt;
#include &lt;fstream&gt;

using namespace std;

int main() {
    fstream inf( "ex.txt", ios::in );
    while( !inf.eof() ) {
        std::cout &lt;&lt; inf.get() &lt;&lt; "\n";
    }
    inf.close();
    inf.clear();
    inf.open( "ex.txt", ios::in );
    char c;
    while( inf &gt;&gt; c ) {
        std::cout &lt;&lt; c &lt;&lt; "\n";
    }
    return 0;
}
</code></pre>

<p>I'm really confused about <code>eof()</code> function. Suppose that my ex.txt's content was:</p>

<pre><code>abc
</code></pre>

<p>It always reads an extra character and shows <code>-1</code> when reading using <code>eof()</code>. But the <code>inf &gt;&gt; c</code> gave the correct output which was 'abc'? Can anyone help me explain this?</p>
