可以用atof()这个函数,但是这个函数的参数是char*类型的,因此需将string类型强制转换,方法为在函数的参数中写成 const_cast<const char *>(str.c_str())

string str = "1.26";
double d = atof(const_cast<const char *>(str.c_str()));

相关文章:

  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-10-12
猜你喜欢
  • 2022-02-23
  • 2021-05-30
  • 2022-12-23
  • 2021-11-22
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案