如何在c ++中将对象数组的数据类型转换为int

问题描述 投票:0回答:1
for (i=0;i<y;i++)
{
stringstream ss(student[i].getstudent());
int MARK;
ss>>MARK;

cout<<student[i].getstudent()/2<<endl;
}

这是将对象数组中的数据类型转换为int的正确方法吗?我已经尝试了很多次,但它没有奏效。

c++ arrays
1个回答
3
投票

是的,在C ++之前,你会使用stringstreamstd::string转换为intatoi()

如果您有权访问C ++ 11,我建议使用std::stoi()

© www.soinside.com 2019 - 2024. All rights reserved.