title: file i/o infinite loop c++ eof
body: <p>I have started working on a program, and for the life of me I can't find a bug which continuously searches the eof and doesn't end. It is most certainly a problem with my fileread and widthcount functions, and they most likely have the same error. Is there a fix for this? It just keeps looping.</p>
  
  <p>The file input is this</p>
  
  <pre><code>12.43 62.38 Los Angeles
  21 59 Columbus, Ohio
  0 15.58 Green Bay, Wisconsin
  </code></pre>
  
  <p>This continues for another 10 lines.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  void fileread(ifstream &amp;ifFile, char newline, double &amp;temp1, double &amp;temp2, string city);
  void widthcount(ifstream &amp;ifFile, int &amp;maxCount, char newline);
  
  int main() {
     double temp1, temp2, minTemp, maxTemp;
     int maxCount;
     char newline=' ';
     string FileRead, city;
     ifstream ifFile;
  
     cout &lt;&lt; "Please enter the location of the input file: ";
     cin &gt;&gt; FileRead;
  
     ifFile.open(FileRead.c_str());
  
     if (ifFile.fail()) {
         perror(FileRead.c_str());
         exit(1);
     }
  
     widthcount(ifFile, maxCount, newline);
  
     while(!ifFile.eof()) {
         widthcount(ifFile, maxCount, newline);
     }      
  
     ifFile.close();
  
     ifFile.open(FileRead.c_str());
  
     fileread(ifFile, newline, temp1, temp2, city);
  
     while(!ifFile.eof()) {
         fileread(ifFile, newline, temp1, temp2, city);
  
         cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; city
               &lt;&lt; right &lt;&lt; setw(6) &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; temp1
               &lt;&lt; right &lt;&lt; setw(6) &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; temp2 &lt;&lt; endl;
  
     }
  
  }
  
  void fileread(ifstream &amp;ifFile, char newline, double &amp;temp1, double &amp;temp2, string city) {
     int charcount = 0;
  
     ifFile &gt;&gt; temp1 &gt;&gt; temp2;
  
     while (newline == ' ')
         ifFile.get(newline);
     while (newline != '\n' || !ifFile.eof()) {
         charcount++;
         ifFile.get(newline);
     }
  }
  
  void widthcount (ifstream &amp;ifFile, int &amp;maxCount, char newline) {
     double temp1, temp2;
     int charcount = 0;
     ifFile &gt;&gt; temp1 &gt;&gt; temp2;
     ifFile.get(newline);
     while (newline != '\n' &amp;&amp; !ifFile.eof()) {
         charcount++;
         ifFile.get(newline);
         cout &lt;&lt; newline;
     }
  
     if (charcount &gt; maxCount)
      maxCount = charcount;
  }
  </code></pre>