可能重复:
getline 不要求输入?
在我的程序中发生了一些独特的事情。以下是一些命令集:
cout << "Enter the full name of student: "; // cin name
getline( cin , fullName );
cout << "\nAge: "; // cin age
int age;
cin >> age ;
cout << "\nFather's Name: "; // cin father name
getline( cin , fatherName );
cout << "\nPermanent Address: "; // cin permanent address
getline( cin , permanentAddress );
当我尝试将此代码段与整个代码一起运行时。输出程序的工作方式如下:
输出:
Enter the full name of student:
Age: 20
Father's Name:
Permanent Address: xyz
如果你注意到了,程序没有问我全名,而是直接问我年龄。然后它也跳过了父亲的名字,问了永久地址。 这可能是什么原因?
我很难发布整个代码,因为它太大了。