title: How to move from the end of the file to the beginning in c++
body: <p>Im having a small problem with my code. I have been trying to read some information from the end of a random access file then repositioning the cursor at the beginning of the file. So far seekg has not been working. Here is my code:</p>
  
  <pre><code>void main ()
  {
      AssignData FileOut;
      AssignData FileIn;
  
      ofstream OutData("Data.dat", ios::out | ios::app | ios::binary);
      ifstream InData("Data.dat", ios::in);
  
      cout &lt;&lt;"Writing to file" &lt;&lt; endl;
  
      if (!OutData)
      {
           cout&lt;&lt;"File does not exist"&lt;&lt;endl;
       exit(1);
      }
  
      //read through file
  
      while (InData.read( reinterpret_cast&lt; char * &gt;( &amp;FileIn ),sizeof( AssignData ) ))
      {                        
      }
  
      FileIn.DisplayFileContent();//displays the last line in the file
  
      FileOut.setInfo();//allows user to add another record
  
      //Writes record to file
      OutData.write( reinterpret_cast&lt; const char * &gt;( &amp;FileOut ), sizeof(AssignData) );                                        
  
      OutData.close();
      cout &lt;&lt; endl&lt;&lt;endl;
      //Reads the first record from the file
  
      InData.seekg(0);
  
      while (InData.read( reinterpret_cast&lt; char * &gt;( &amp;FileIn), sizeof(AssignData) ))
      {
      // display record
          if ( (FileIn.getID() != 0) || (FileIn.getID()!=NULL) )
      {
          FileIn.DisplayFileContent();
      }                         
      }
  
      InData.close();
  
      _getch();
      exit(0);
  }
  </code></pre>