c++中类型中公用赋值函数为什么第二个对象无法赋值?

简单的C++入门程序,求解为何stu2的数据不能被输入?

#include
//#include
using namespace std;

class Student
{
private:
    int num;
    int score;
public:
    void setdata()
    {
        cin >> num;
        cin >> score;
    }
    void display()
    {
        cout << "num=" << num << endl;
        cout << "score=" << score << endl;
    }
};
Student stu1, stu2;
int main()
{
    stu1.setdata();
    stu2.setdata();
    stu1.display();
    stu2.display();
    system("pause");
    return 0;
}

输入:1001 98.5
1002 76.5
输出的stu2是0?

因为score是int吧,换成double就可以了

score是整型,而你输入的是浮点型,不匹配。改为 flaot score;

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^