 <p>Change <code>while(infile.is_open())</code> to <code>while(infile)</code>. Then you can remove the redundant eof test at the end.</p> <p>It's still open even if you've encountered an error or reached the end of file. It's likely you are in a scenario where failbit is getting set (getline returns nothing), but eof has not been encountered, so the file never gets closed, so your loop never exits. Using the <code>operator bool</code> of the stream gets around all these problems for you.</p>