fstream end of file question
<p>I am reading in multiple files. There are roughly 300 of these files. For some reason, if I set the loop to run over 3 iterations, the while loop which is supposed to iterate through each line becomes infinite. My question is: Is there somthing I am forgetting to include in my while loop? For now I am simply trying to read one line at a time, eventually saving some data in the output file. Or is it possible that there is something contained in the data files that is not letting the program reach the end of the file? </p>

<pre><code>ifstream inFile;
ofstream outFile;
char outputFilename[] = "output.txt";
int i;

outFile.open(outputFilename, ios::out);

for (i = 1; i &lt; 4; i++) {
    stringstream inputFilename;
    inputFilename &lt;&lt; "data/" &lt;&lt; i &lt;&lt; ".txt";
    inFile.open(inputFilename.str().c_str(), ios::in);
    if (!inFile) {
        cout &lt;&lt; "Error opening input files" &lt;&lt; endl;
        exit(-1);
    }

    char buffer[256];
    while (!inFile.eof()) {
        cout &lt;&lt; "HEY";
        inFile.getline(buffer, 100);
    }
    inFile.close();
}
outFile.close();
</code></pre>

<p>Update: This works much better</p>

<pre><code>char buffer[256];
    while (!inFile.eof()) {
      inFile &gt;&gt; buffer;
    }
</code></pre>
