#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    21
    Rep Power
    0

    trouble with infile


    hi, im having trouble with the function createvideostore in mytestVideoStore.cpp . It loads in all the names from the customerDat.txt correctly but for some reason the movie info for each person is wrong.....why is it going wrong, attached all files as a zip file.
    Attached Files
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Try this (inside your createvideoStore() routine):

    Code:
        //there needs to be lots of error checking to ensure
        //that corrupted input data does not cause program to crash!
        while(!getline(infile2, cName).fail()){
            newCustomer.setName(cName);
            infile2 >> num;
            getline(infile2, mName);//dummy to clear linefeed
            if(num > 0){
                for (int i=0; i<num; i++){
                    getline(infile2, mName);
                    newCustomer.addTitle(mName);
                }
            }
            newCustomer.setNumCheckedOut(num);
            videoStore.addCustomers(newCustomer);
        }
    Your use of 'get' was not doing what you wanted. get() is used specifically if you do NOT want to clear the end of line delimiter (see http://www.cplusplus.com/ref/iostrea...m/getline.html).

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo