The problem is that you are mixing getline
with cin >>
input.
When you do cin >> age;
, that gets the age from the input stream, but it leaves whitespace on the stream. Specifically, it will leave a newline on the input stream, which then gets read by the next getline
call as an empty line.
The solution is to only use getline
for getting input, and then parsing the line for the information you need.
Or to fix your code, you could do the following eg. (you'll still have to add error checking code yourself) :
cout << "Enter the full name of student: "; // cin name
getline( cin , fullName );
cout << "\nAge: "; // cin age
int age;
{
std::string line;
getline(cin, line);
std::istringstream ss(line);
ss >> age;
}
cout << "\nFather's Name: "; // cin father name
getline( cin , fatherName );
cout << "\nPermanent Address: "; // cin permanent address
getline( cin , permanentAddress );