The problem here is that when you use the input operator >>
it will leave the newline after the last number for the first record. This means that the next getline
call will read that newline as an empty line, and then the numbers will fail to read.
There are a couple of ways to solve this. The first is to discard all text in the input until newline after reading the last number in the record. For this you can do e.g.
// All other input in loop
input.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Read about the ignore
function.
Another way is to read the second line, complete, and put it into an std::istringstream
and then read out the numbers from it:
// Reading the name...
std::string numbers;
std::getline(input, numbers);
std::istringstream istr(numbers);
istr >> num;
people[i].setage(num);
// ...
Also note that the third argument to std::getline
already defaults to a newline, so if you're using it to read lines, then you don't need to provide it.