Problem in reading file
May 27, 2017 at 2:18pm May 27, 2017 at 2:18pm UTC
Hi everyone ,I am writing a program that writes and then read the details in a file for multiple users .My program is working fine but in file it only displays the data not the category in which it falls.
for example it reads on file like this
(Ali
1234243
452432134)
But i want to display like this
(Name:Ali
Mobile no:1234243
Account no:452432134)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#include<iostream>
#include<fstream>
using namespace std;
struct User
{char name[50];
int accountno;
int cellno;
int accountbalance;
char accounttype[10];
};
int main()
{int i,n;
User x[20];
cout<<"Enter no of Users:" ;
cin>>n;
ofstream outfile;
outfile.open("D:\\ATM info.txt" );
for (i=0;i<n;i++)
{
cout<<"Name:" <<endl;
cin>>x[i].name;
outfile<<x[i].name<<endl;
cout<<"Account no:" <<endl;
cin>>x[i].accountno;
outfile<<x[i].accountno<<endl;
cout<<"Cell no:" <<endl;
cin>>x[i].cellno;
outfile<<x[i].cellno<<endl;
cout<<"Account Balance:" <<endl;
cin>>x[i].accountbalance;
outfile<<x[i].accountbalance<<endl;
cout<<"Account Type:" <<endl;
cin>>x[i].accounttype;
outfile<<x[i].accounttype<<endl;
}
cout<<endl;
outfile.close();
ifstream infile;
infile.open("D:\\ATM info.txt" );
cout<<"Account Details:\n" <<endl;
for (i=0;i<n;i++)
{cout<<"Name:" <<endl;
infile>>x[i].name;
cout<<x[i].name;
infile>>x[i].accountno;
cout<<"Account no:" <<x[i].accountno<<endl;
infile>>x[i].cellno;
cout<<"Cell no:" <<x[i].cellno<<endl;
infile>>x[i].accountbalance;
cout<<"Account Balance:" <<x[i].accountbalance<<endl;
infile>>x[i].accounttype;
cout<<"Account type:" <<x[i].accounttype<<endl;
}
infile.close();
system("pause" );}
May 27, 2017 at 11:59pm May 27, 2017 at 11:59pm UTC
Then you have to use "Mobile no:" in your output command.
Formatting your code would go a long way towards making it readable.
May 28, 2017 at 12:57pm May 28, 2017 at 12:57pm UTC
can u specoify the line plz
May 28, 2017 at 1:32pm May 28, 2017 at 1:32pm UTC
its ok i got it thanks
Topic archived. No new replies allowed.