samedi 4 juillet 2020

while reading from a infile using getline after the file ends prevoiusline is repeted in output; [duplicate]

while running the code the lastline of "account.txt" is repeating.

accnt.txt

1234 | harishankar Behera | Current | 700

6578 | jhsah asdhiu | Current | 500

output

enter the account number

2

Balance Detalis...

1234 harishankar Behera Current 700

6578 jhsah asdhiu Current 500

jhsah asdhiu Current 500

void display_accnt(int)
    {
        bool flag=false;
        account ac;
        ifstream ifile;
        string accnt,name,type,deposit;
        ifile.open("account.txt",ios::binary);
        if(!ifile)
        {
            cout<<"FILE NOT FOUND"<<endl;
            return;
        }
        cout<<"Balance Detalis..."<<endl;
        while(!ifile.eof())
        {
            [enter image description here][1]
            getline(ifile,accnt,'|');
            getline(ifile,name,'|');
            getline(ifile,type,'|');
            getline(ifile,deposit,'\n');
            cout<<accnt<<" "<<name<<" "<<type<<" "<<deposit<<endl;


  [1]: https://i.stack.imgur.com/I8SX2.png

Aucun commentaire:

Enregistrer un commentaire