0

I am a beginner at programming. I am having problems updating records in a Bank Management System project I am making using C++. So I made a test case on the side discovering something weird. When I access a record and try to print only the first three entries. There are no problems.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
   fstream file(“t.txt”);

   int a; string b; int c;
   int p = 1;
   while(file>>a>>b>>c){
       if(a == 1){
           cout <<a<<b<<" "<<c;
       }
   }

   return 0;
}

But when I try to print the fourth entry, it does not print anything at all.

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
   fstream file(“t.txt”);

   int a; string b; int c; int d;
   int p = 1;
   while(file>>a>>b>>c>>d){
       if(a == 1){
           cout <<a<<b<<" "<<c<<d;
       }
   }

   return 0;
}

Here is the text file;

0 husnain 20
1 husnain 21 22222222
2 husnain 22
3 husnain 23
4 husnain 24

Also, is there a way to print the full name with a space between first and last name?

0 Answers0