Sloan Anderson
Sloan Anderson

Reputation: 93

C++ while(getline()) not working properly

I am using getline to start reading in info from a file. The problem is that it will never enter the while loop, even though there is data in the file to read. Does anyone see what the issue might be? I know my code may not be the best formatted, but right now I am strictly concerned with the while(getline())

void loadPatients(Doctor Doctor[], int size)
{
    std::ifstream patientFile;
    Patient** patientInfo;
    std::string Address, DoctorId, Id, Name, PhoneNumber,junk;
    int patientNumber;
    patientInfo = new Patient*[size];
    for (int b = 0; b < size; b++)
        patientInfo[b] = new Patient[10];

    for (int i = 0; i < size; i++)
    {
        DoctorId = Doctor[i].getId();
        patientFile.open(DoctorId);
        patientNumber = Doctor[i].getNumberOfPatient();
        for (int a = 0; a < patientNumber; a++)
        {
            while (getline(patientFile, Name))
            {
                getline(patientFile, Id);
                getline(patientFile, Address);
                getline(patientFile, PhoneNumber);
                getline(patientFile, DoctorId);
            }
            patientInfo[i][a].setAddress(Address);
            std::cout << Address;
            patientInfo[i][a].setName(Name);
            patientInfo[i][a].setDoctorId(DoctorId);
            patientInfo[i][a].setId(Id);
            patientInfo[i][a].setPhoneNumber(PhoneNumber);
        }
        patientFile.close();

    }

Upvotes: 1

Views: 868

Answers (1)

Sloan Anderson
Sloan Anderson

Reputation: 93

patientFile.open(DoctorId) needs the .txt extension to it.. so patientFile.open(DoctorId+".txt")

Upvotes: 1

Related Questions