Hi all,,

A module of my Bank Management System which should display the user account details after successfuly entering his/her details calls to a function:

void display_acc(int n)
{
account acc;
int flag=0;
ifstream inFile;
inFile.open("account.txt",ios::in);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<"\nBALANCE DETAILS\n";
while(inFile.read((char *) &acc, sizeof(account)))
{
if(acc.ret_acno()==n)
{
acc.show_account();
flag=1;
}
}
inFile.close();
if(flag==0)
cout<<"\n\nAccount number does not exist";
}

where

void account::show_account()
{
cout<<"\nAccount No. : "<<acno;
cout<<"\nAccount Holder Name : ";
cout<<name;
cout<<"\nType of Account : "<<type;
cout<<"\nBalance amount : "<<&account::deposit;
}

and

int account::ret_acno()
{
return acno;
}

the name of my class is account which contains public functions declarations and other variables:
But on run it says "File could not be open !! Press any Key..."

What I wanna know is that my account.txt is a text file and contains data in unreadable format except the string values....
1.How should i achieve human readable data format ?
2.Is there any mechanism where i should connect my this C++ program to SQL database where i should create an account table and auto-increment it for users having each users required data and then retrieve on display_acc function i.e on write_acc should enter acc.no,acc.holder name etc and on demand should retrieve it from MYSQL database.
Please ensure me to do so...

account.txt contains data like despite of declaring it *.txt:
ÌÌÌÌÌÌÌÌÌÌÌ° CÌÌÌ ÌÌÌÌÌÌÌÌÌÌ̤ CÌÌÌ ˜E« javed ÌÌÌÌÌÌÌÌÌÌ ÌÌÌÌX SÌÌÌ

Recommended Answers

All 3 Replies

When the file fails to open it means one of two things: (1) you mispelled the name of the file, or (2) the file isn't in the same folder as where the program is running.

Questiion 1: Write the data out in a different format. write() just writes out the data exactly as it appears in memory, which is why write() works so fast. If you want the file readable, then don't use write() but use a series of cout calls.

Question 2: Yes, but it's pretty complicated process. First you have to learn the Structured Query Language (SQL), there are many tutorials, just google for them. There are also several entire books on that topic that you can get from amazon.com or your local book store.

Unless this is a requirement of your assignment I don't think it will be worth your time/effort to implement SQL in this program. Learn it if you wish, but IMO it's overkill.

But the fil3 is unable to open despite of being in the same directory where the program is running and correctly-spelled...Irritating me

What is fil3? You are oppening account.txt in inFile.open("account.txt",ios::in);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.