Rewind ifSteam in C++
<p>I'm aware this has been asked a few time before and I read the threads related to it but the solutions there didn't work for me.</p>

<pre><code>ifstream myFile;

myFile.open("largefile.txt");

    if (myFile.is_open())
        {
            while (!myFile.eof( ))  //step through each line until end of file
            {
                myFile&gt;&gt; str;
                if(str.size() &lt; 5){
                    amount++;
                }
            }
        }

    myFile.seekg(0, ios::beg);

if (myFile.is_open())
        {
            for(int i=0; i != random_integer; i++)  //step through each line until random line reached
            {
                myFile&gt;&gt; str;
                if(i == random_integer-1){
                cout &lt;&lt; "\n";
                cout &lt;&lt; str;
                cout &lt;&lt; "\n";
                cout &lt;&lt; str.size();
                }
            }
        }
        myFile.close();
</code></pre>

<p>I read that using EOF in the while statement was a bad idea, whats the alternative? And how can I rewind for the second loop as seekg isn't working out, I don't want to have to close the file and open again, and the file is to large to read into an array really? </p>

<p>TIA, I'm sure this is an easy fix I'm just very new to C++. </p>
