首页 > 解决方案 > 如何在不使用拆分的情况下将 N DOUBLE 数字与字符串分开?

问题描述

我想知道如何通过以下方式将多个数字从单个字符串中分离出来,或者以另一种方式,但以非常短的方式:

void separate(string product)
{
    std::string orbits ("365.24 29.53 234.455");
    std::string::size_type sz;     // alias of size_t
    double earth = std::stod (orbits,&sz);
    double moon = std::stod (orbits.substr(sz));
    std::cout << "The moon completes " << (earth/moon) << " orbits per Earth year.\n";
}

输出:

12,3684

标签: c++

解决方案


推荐阅读