I am reading the lines in my .txt file. I got a problem in the last line. It wont read it. I have used eof()
which is not a good practice. So I tried using the reading part as the parameters of my loop.
Here it is:
void browse(int accNum)
{
int acnum,pin;
float bal;
string fname,lname;
ifstream file;
file.open("acc.txt",ios::in);
if(file.is_open())
{
while(file>>acnum>>pin>>fname>>lname>>bal)
{
if(acnum==accNum)
{
cout<<"ACCOUNT NUMBER: "<<acnum<<"\nNAME: "<<fname<<" "<<lname<<"\nBALANCE: "<<bal;
break;
}
else
{
cout<<"ERROR";
}
}
}
else
{
cout<<"FILE NOT OPEN";
}
file.close();
}
I've changed it to while((file >> acnum >> pin >> fname >> lname >> bal) != NULL)
. It is still not working. What is the solution for this?
Here is the content of the database:
1111111111 4324 James Doe 300000
2222222222 0123 Eric Doe 10000
1234567899 1234 John Doe 444444