This loop is executing more iterations than is expected
<p>I am having problems with the following code. What I expect is for the <code>do-while</code> loop to execute 4 times, once for each line of the text file it is reading in, but in reality is it executing five time, which is resulting in a segfault later in the program. What am I doing wrong here that's causing it to execute the extra iteration? I've tried replacing he <code>do-while</code> with a simple <code>while</code> loop but the result is the same.</p>

<pre><code>int count = 0;
string devices[4];
string line;
ifstream DeviceList;
DeviceList.open("devices/device_list.txt");
do
{
 getline(DeviceList, line);
 devices[count] = line;
 count ++;
} while(!DeviceList.eof());
</code></pre>

<p><code>device_list.txt</code> contains the following:</p>

<pre><code>WirelessAdaptor
GPU
CPU
Display
</code></pre>
