Hi, I'm having problem reading a sequential file, I have done some searches all without any positive result. I trying to read a sequential file, but the problem is that the last record is read doubly. Any help would be appreciate.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main () {
string identifier,name,address,firtsenrollment, dummy;
int creditApproved;
ifstream myfile ("Student Registration Keyboard Out.txt");
myfile.unsetf(ios::skipws);
if (myfile.is_open())
{
while ( !myfile.eof() )
{
getline(myfile, identifier);
getline(myfile, name);
getline(myfile, address);
getline(myfile, firtsenrollment);
myfile >> creditApproved;
getline(myfile,dummy);
cout << identifier << endl;
cout << name << endl;
cout << address << endl;
cout << firtsenrollment << endl;
cout << creditApproved << endl;
}
myfile.close();
}
else cout << "Unable to open file";
cout << "Press enter to close the window.";
cin.ignore ( cin.rdbuf()->in_avail() );
cin.get( );
return 0;
}
870-06-4143
John Phil
Stree 5 NY, 985965
08-07-06
36
515-58-5867
Smith All
SAfasfas sfsafsadf, Pakistan
08-07-06
65
323-47-6547
Way Yo
Palm, Hawwai
41-24-65
34