Explanation why it doesn't return what it should : <p>I have function that gets info about students from a file "Curent.txt".</p>

<p>That's the struct:</p>

<pre><code>struct students {
    string CodSt;
    string NumeSt;
    string PrenSt;
    string DenDisc1;
    string MedCD1;
    string DenDisc2;
    string MedCD2;
    string DenDisc3;
    string MedCD3;
} student[50];
</code></pre>

<p>That's the function:</p>

<pre><code>void getStudents() {
int i = 0;
ifstream ifs("Curenta.txt");
while(!ifs.eof()) {
    ifs &gt;&gt; student[i].CodSt &gt;&gt; student[i].NumeSt &gt;&gt; student[i].PrenSt &gt;&gt; student[i].DenDisc1
        &gt;&gt; student[i].MedCD1 &gt;&gt; student[i].DenDisc2 &gt;&gt; student[i].MedCD2 &gt;&gt; student[i].DenDisc3
        &gt;&gt; student[i].MedCD3;
    if(!ifs.eof()) {
        i++;
        cout &lt;&lt; i;
    }
    var = i;
    ifs.close();
}
</code></pre>

<p>And in "Curent.txt" i have only this:</p>

<pre><code>9 8 1 1 6 1 1 1 1
3 1 1 1 4 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 7 1 1 1 1
</code></pre>

<p>My question is why when I output variable "i", the value is just 1..</p>

<p>Thanks in advance.</p>
