为什么在for循环里面 getScore()的值是错误的
#include <iostream>
#include<cstdlib>
#include<string>
using namespace std;
class student
{
public:
void setName(string _name)
{
m_strName=_name;
}
string getName()
{
return m_strName;
}
void setGende(string _gende)
{
m_strGende=_gende;
}
string getGende()
{
return m_strGende;
}
int getScore()
{
return m_iScore;
}
void study(int _score)
{
m_iScore+=_score;
}
private:
string m_strName;
string m_strGende;
int m_iScore;
};
int main( )
{
student stu;
cout<<"input student name:"<<endl;
string name;
getline(cin,name);
stu.setName(name);
//cin.sync();
//cout<<stu.getName()<<endl;
cout<<"input gende:"<<endl;
string gende;
getline(cin,gende);
stu.setGende(gende);
//cin.sync();
//cout<<"input score"<<endl;
int score;
for (int i=1;i<4 ;i++ )
{ cout<<"input score"<<i<<"科"<<endl;
cin>>score;
stu.study(score);
}
//cin.sync();
/*int score;
cin>>score;
stu.study(score);
cin>>score;
stu.study(score);
cin>>score;
stu.study(score); 这样做可以值是正确的 为什么上面for循环 值是错误的 求解*/
cout<<stu.getName()<<"\n"<<stu.getGende()<<"\n"<<stu.getScore()<<endl;
return 0;
}