error: cannot convert ‘std::__cxx11::string {aka std::__cxx11::basic_string}’ to ‘float’

最近在调试一个c++代码,遇到了一个函数中需要返回一个数值,但是这个数值的类型是string型,我的函数是int型,所以这里就出现了标题的错误,经过改进成功解决,代码如下:
错误代码片段

int get_dep()
{
string strFrameNo1;
int dep;
ss>>strFrameNo1;
dep=(int)strFrameNo1;
return dep;
}

改进后的代码:

int get_dep()
{
string strFrameNo1;
int dep;
ss>>strFrameNo1;
dep=atoi(strFrameNo1.c_str());
return dep;
}

猜你喜欢

转载自blog.csdn.net/weixin_42535742/article/details/91041044