getline函数未在gdb中接受输入

时间:2019-11-09 15:02:13

标签: c++ gdb

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中)

0 个答案:

没有答案