protected:
string department;
public:
void get_data(){
cout<<"enter the name:"<<endl;
cin>>name;
cout<<"enter the salary"<<endl;
cin>>salary;
cout<<"enter the department"<<endl;
getline(cin,department);
这种格式不作为部门的输入。但是,如果将getline语句放在所有这样的语句的顶部:
protected:
string department;
public:
void get_data(){
cout<<"enter the department"<<endl;
getline(cin,department);
cout<<"enter the name:"<<endl;
cin>>name;
cout<<"enter the salary"<<endl;
cin>>salary;
然后将其输入部门。为什么会这样?(在gdb中)