for (i=0;i<y;i++)
{
stringstream ss(student[i].getstudent());
int MARK;
ss>>MARK;
cout<<student[i].getstudent()/2<<endl;
}
这是将对象数组中的数据类型转换为int
的正确方法吗?我已经尝试了很多次,但它没有奏效。
是的,在C ++之前,你会使用stringstream
从std::string
转换为int
或atoi()
。
如果您有权访问C ++ 11,我建议使用std::stoi()
。