如果vs版本比较低,会不支持一些std类型转换函数(vs2008就不支持),比如:
std::to_string \\数字转字符串
std::stoll \\字符串转数字
而且项目碰巧用boost库,可以考虑用下面的的方法来进行类型转换
首先添加头文件:
#include <boost/lexical_cast.hpp>
boost::lexical_cast<目标类型>(需要转换的变量)
代码
std::string strTodouble = "6798987.65748723135";double doubleFromstr = boost::lexical_cast<double>(strTodouble);printf("%.9f\n", doubleFromstr);std::string strToi64 = "671321312398987";int64_t i64FromStr = boost::lexical_cast<int64_t>(strToi64);std::cout << i64FromStr << std::endl;int64_t i64ToStr = 1431313564521;std::string strFromI64 = boost::lexical_cast<std::string>(i64ToStr);std::cout << strFromI64;