title: Read a file twice in C++ because of eof?
body: <p>I read numbers from a file, apply 3 functions and print out to another file:</p>
  
  <pre><code>int main(int argc, char** argv) {
      std::ifstream fin;
      fin.open("input.txt");
  
      std::ofstream fout;
      fout.open("output.txt", std::ios::app);
  
      char arr[50];
      int a,b;
      int N;//number to factor
  
      while (!fin.eof()){
          //Print backward
          fin &gt;&gt; arr;
          PrintBackward( arr );
          fout &lt;&lt; endl;
  
          //Greatest common divisor
          ((fin &gt;&gt; a) &gt;&gt; b);
          fout &lt;&lt; gcd( a, b );
          fout &lt;&lt; endl;
  
          //Find prime factor
          fin &gt;&gt; N;
          PrimeFactor(N);
          fout &lt;&lt; endl;     
      }
  
      fin.close();
      fout.close();
  
      return 0;
  }
  </code></pre>
  
  <p>After running, the result is duplicated:</p>
  
  <pre><code>olleh
  3
  2 3 7 
  olleh
  3
  2 3 7
  </code></pre>
  
  <p>I read a similar article but it's about reading into 1 variable so it seems not to be feasible.</p>
  
  <p>If I set a <code>break</code> at the end of the <code>while</code> loop, it's fine. Is there any way not to use <code>break</code>?</p>