因此,当我运行此代码时,在while循环的第一次迭代之后,我收到运行时错误并退出程序。我知道问题在于while循环的第二次迭代中的getline(输入,空白),但我不知道如何解决它。如果有人帮助我,我将不胜感激。提前谢谢!
int main() {
ifstream input("Airline.CSV");
int count = 0;
Passenger *p [400];
string firstName, lastName, e;
char seatLetter;
int rowNumber;
stringstream inputf;
//count = 0;
string blank;
while (getline(input, blank)){
inputf << blank;
getline(inputf, lastName, ',');
getline(inputf, firstName, ',');
getline(inputf, e, ',' );
rowNumber = atoi(e.c_str());
getline(inputf, e, ',');
seatLetter = e[0];
getline(inputf, e, ' ');
p[count] = new Passenger (firstName, lastName, rowNumber);
inputf.clear();
count++;
}
for (int counter = 0; counter < 2; counter++) {
if (p[counter]->getSector() == "First Class")
p[counter]->list();
}
for (int counter = 0; counter < 2; counter++) {
if (p[counter]->getSector() == "Business Class")
p[counter]->list();
}
delete [] p;
return 0;
}