我无法弄清楚我的简单 IO 问题是什么:
这是我执行 IO 的代码:
cout << "Enter an Employee name: ";
getline(cin, empName);
cout << "Employee Position: " ;
cin >> empPos;
cout << "Enter the Number of Years of Experience: ";
cin >> numOfExp;
cout << "Enter the deprtment Number: ";
cin >> deptNum;
这是我的错误输出:第一次读取名称时一切都很好,但第二次看起来像是自动传递到名称中,而不要求用户输入任何名称。
这是我的输出:
Name: Unknown
Department Number: 0
Employee Position: E
Years of Experience: 0
Salary: 0
Total Number of Employees: 1
Enter an Employee name: arasd d
Employee Position: s
Enter the Number of Years of Experience: 12
Enter the deprtment Number: 12
Name: arasd d
Department Number: 12
Employee Position: s
Years of Experience: 12
Salary: 0
Total Number of Employees: 1
Enter an Employee name: Employee Position:
如您所见,最后一行是问题所在;知道如何解决这个问题吗?