-
file IO problem
I'm having trouble opening a file in my atm program. A quick rundown:
So far, my program opens a file when the program executes with a list of usernames and pin numbers. After it reads the contents of the file, it asks the user for his username. If there is a match, it asks for his pin number to complete the validation. Then, another function takes the person's username (I used the variable "bankId"), adds the extension ".dat" and should then open the file called 'username'.dat (Username being the variable bankId)
The file is not being opened however. Below is the function that should open the file. I am new to classes and this is my first semester of programming, so I'm hoping it's something minimal that I'm just looking over. If you need more code than what I've posted please let me know. Thanks.
Code:
void customer::openCustomerFile(ifstream& fin) {
char suffix[5] = ".dat";
char filename[25];
strcpy (filename, bankId);
strcat (filename, suffix);
fin.open( filename, ios::in );
if ( !fin ) {
cout<< "There was an error opening that file." << endl;
exit(1);
}
}
-
I'm not sure why my posted added a little smiley face to my code, but the function is called "openCustomerFile".
-
Your code looks fine, the problem must be elsewhere.