file IO problem

This is a discussion on file IO problem within the C++ Programming forums, part of the General Programming Boards category; I'm having trouble opening a file in my atm program. A quick rundown: So far, my program opens a file ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    2

    Angry 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);
             }
    }

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    2
    I'm not sure why my posted added a little smiley face to my code, but the function is called "openCustomerFile".

  3. #3
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Your code looks fine, the problem must be elsewhere.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Problem reading file
    By coder_009 in forum C Programming
    Replies: 10
    Last Post: 01-15-2008, 12:22 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. Totally puzzling IO problem
    By Vorok in forum C++ Programming
    Replies: 5
    Last Post: 01-06-2003, 06:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21