title: Off by one error in while loop with eof()
body: <p>I have an off-by-one error in the following piece of C++ code and I can not figure it out. Can anybody please help. I have the code and its output below. Best.</p>
  
  <pre><code>double* alloc_Array=new double[m_int_NumChann*m_int_NumSamples];
  int int_SizeArray=int(0);
  std::ifstream File;
  File.open(m_char_Address);
  if(File.is_open()){
      std::cout&lt;&lt;"input file opened...\n";
      int i=int(0);
      do{
          File&gt;&gt;alloc_Array[i];
          i++;
      }while(!File.eof());
      int_SizeArray=i;
  }else{
      std::cerr&lt;&lt;"ERROR: input file can't be opened.\n";
      system("pause");
  }
  File.close();
  if((m_int_NumChann*m_int_NumSamples)!=int_SizeArray){
      std::cerr&lt;&lt;"WARNING: number of samples multiplied by number of channels is not equal to total data points in the input file:\n";
      std::cerr&lt;&lt;"       number of samples in each channel = "&lt;&lt;m_int_NumSamples&lt;&lt;'\n';
      std::cerr&lt;&lt;"       number of channels = "&lt;&lt;m_int_NumChann&lt;&lt;'\n';
      std::cerr&lt;&lt;"       total data points by multiplication = "&lt;&lt;m_int_NumSamples*m_int_NumChann&lt;&lt;'\n';
      std::cerr&lt;&lt;"       number of data points in the input file = "&lt;&lt;int_SizeArray&lt;&lt;'\n';
      system("pause");
  }
  </code></pre>
  
  <h2>Output:</h2>
  
  <pre><code>   input file opened...
  
     WARNING: number of samples multiplied by number of channels is not equal to tota
     l data points in the input file:
  
     number of samples in each channel = 77824
  
     number of channels = 11
  
     total data points by multiplication = 856064
  
     number of data points in the input file = 856065
  
     Press any key to continue . . .
  </code></pre>