2017-01-27 5 views
1

getlineを使用してファイルから情報を読み込み始めました。問題は、読み込むファイルにデータがあるにもかかわらず、whileループに入ることがないことです。問題が何であるか誰にでも見えますか? ..私は私のコードは最高の書式設定ではないかもしれないけど、今の私はしばらくの間で(getlineの())C++ 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(); 

    } 
+0

whileループに到達しない場合は、forループ終了条件をチェックするので、sizeとpatientNumberをチェックしてください。coutステートメントを使用して、入力されていない箇所を確認してください –

+0

私はおそらくそれを述べているはずですが、それはwhileループの前の行に到着しますが、それを入力しません –

+0

while(patientFile.good())を試して、getline(patientFile、Name)をinsideしばらくして、それが内側に入るかどうかを見てくださいeループ –

答えて

1

patientFile.open(DoctorId)がそれに.txt拡張子を必要とする厳密心配ですpatientFileので、 .open(DoctorId + ".txt")

関連する問題