I use cin.ignore() to remove the leftover newline before calling getline: cin >> age; cin.ignore(); getline(cin, name); now works correctly. The ignore() discards one character from the buffer.
The full syntax is cin.ignore(count, delimiter), where count is how many characters to discard and delimiter stops early. Calling cin.ignore() with no arguments discards one character.
For safety, use cin.ignore(1000, '\n') to discard up to 1000 characters or until a newline. This clears any extra input the user typed, preventing buffer pollution.