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;
cout<<"File could not be open !! Press any Key...";
cout<<"\nBALANCE DETAILS\n";
while(inFile.read((char *) &acc, sizeof(account)))
cout<<"\n\nAccount number does not exist";


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


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:

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.

Edited 2 Years Ago by Ancient Dragon

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

This article has been dead for over six months. Start a new discussion instead.