尝试在此代码中使用cin员工的全名,但在首次输入后会出现错误
尝试使用char数组和getline,但没有成功
#include <iostream>
#include <string>
using namespace std;
struct employee{
string name;
double salary;
int hoursworked;
};
int main(){
employee employeedata[10];//array of struct to store employee data
for (int i=0; i<10; i++ ) { // receiving employeedata inputs
cout<<"input the data of employee "; cout<<i+1;
cout<<endl;
cout<<"enter name: "; getline(cin,employeedata[i].name);
cout<<endl;
cout<<"enter salary: ";cin>>employeedata[i].salary;
cout<<endl;
cout<<"enter hoursworked: "; cin>>employeedata[i].hoursworked;
cout<<endl;
}
我希望输入10名员工的雇员数据,但是一旦我输入了全名(例如迈克尔·狄更斯),它将停止工作