C++ C++;而(getline())工作不正常

C++ C++;而(getline())工作不正常,c++,ifstream,getline,C++,Ifstream,Getline,我正在使用getline开始从文件中读取信息。问题是它永远不会进入while循环,即使文件中有数据要读取。有人知道问题可能是什么吗?我知道我的代码可能不是最好的格式,但现在我非常关心while(getline()) void loadPatients(医生[],整数大小) { std::ifstream patientFile; 病人**病人信息; std::字符串地址、DoctorId、Id、名称、电话号码、垃圾邮件; int患者编号; patientInfo=新患者*[大小]; 对于(int

我正在使用getline开始从文件中读取信息。问题是它永远不会进入while循环,即使文件中有数据要读取。有人知道问题可能是什么吗?我知道我的代码可能不是最好的格式,但现在我非常关心while(getline())

void loadPatients(医生[],整数大小)
{
std::ifstream patientFile;
病人**病人信息;
std::字符串地址、DoctorId、Id、名称、电话号码、垃圾邮件;
int患者编号;
patientInfo=新患者*[大小];
对于(int b=0;bstd::coutpatientFile.open(DoctorId)需要.txt扩展名..所以patientFile.open(DoctorId+“.txt”)

如果它从未到达while循环,则检查for循环终止条件,因此检查大小和patientNumber…使用cout语句并查看它未输入的位置我已经这样做了,我可能应该提到,它到达while循环之前的行,但未输入while。您可以尝试while(patientFile.good()),并将getline(patientFile,Name)移动到while中,查看它是否进入loopah中,确定它仍然没有进入,因此打开文件时出现问题,然后是,因此检查DoctorId是什么。
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();

    }