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

  • Post author:
  • Post category:其他


最近在调试一个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;
}



版权声明:本文为weixin_42535742原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。