I am trying to read in a .csv file of hotel room reservations. The objects are created correctly, but I am getting an out of range error after the reading in is completed.

I have tried messing around with inFS.ignore() in various places, but it will either mess up some/all inputs alone or that and throw the same error. The only time I can get all correct values is when I omit it completely (as shown above) but then I get this error again. I am confused because im using push_back for the vector so that shouldn't be a range issue. Additionally, I have while loop running while !eof() so I don't think its a file issue either

This is the method I have created to open & read the file

void openFile(string fileName, Hotel h){
ifstream inFS;
inFS.open(fileName);
if (!inFS.is_open()){       
    cout << "File error;" << endl;
    return;
}
else {
    string date;
    string type;
    string name;
    string email;
    string op1;
    string op2;
    getline(inFS, date);
    while(!inFS.eof()){
        getline(inFS, type, ',');
        getline(inFS, name, ',');
        getline(inFS, email, ',');
        getline(inFS, op1, ',');
        getline(inFS, op2, ',');
        char o1 = op1.at(0);
        char o2 = op2.at(0);

        char t1 = type.at(0);                   
        if(t1 == BUNGALOW){
            Bungalow bRoom;
            bRoom.setRoomType(type);
            bRoom.setCustomerName(name);
            bRoom.setCustomerEmail(email);
            bRoom.setViewChoice(o1);
            bRoom.setHoneymoonPackage(o2);
            Room* pointer = &bRoom;
            h.addRoom(pointer);
            cout << "Bungalow created" << endl;
        }
        else if(t1 == KING){
            DeluxeKing kRoom;
            kRoom.setRoomType(type);
            kRoom.setCustomerName(name);
            kRoom.setCustomerEmail(email);
            kRoom.setConciergeFloor(o1);
            kRoom.setParkingGarageAccess(o2);
            Room* kPointer = &kRoom;
            h.addRoom(kPointer);
            cout << "Deluxe King created" << endl;
        }
        else if (t1 == QUEEN){
            StandardQueen qRoom;
            qRoom.setRoomType(type);
            qRoom.setCustomerName(name);
            qRoom.setCustomerEmail(email);
            qRoom.setLargerRoom(o1);
            qRoom.setParkingGarageAccess(o2);
            Room* qPointer = &qRoom;
            h.addRoom(qPointer);
            cout << "Standard King created" << endl;
        }
        else {
            cout << "Received: " << t1 << endl;
        }


    }           


}

} Here is there csv file I am using:

12/01/20
B01,John Smith,[email protected],B,H
B04,Alan Wade,[email protected],G,X
DK03,Susan Slate,[email protected],Y,Y
DK07,Tim Tolee,[email protected],N,Y
Q09,Nicole Thomas,[email protected],Y,Y
Q10,Brown Dole,[email protected],N,Y
0

There are 0 best solutions below