c++ - 如何在不使用拆分的情况下将 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
解决方案
推荐阅读
- r - 使用 family=betar 的 bam 模型 (mgcv) 中的未知错误消息
- flutter - Flutter自动导入扩展文件不起作用
- apache-kafka - 是否可以针对 Schema Registry 中的不同演变更改主题的兼容性类型?
- reactjs - 如何使用带有字母的 react-input-mask?
- c# - 使用切换开关从管理面板中为特定用户隐藏侧边栏菜单
- php - 使用 PHP + Laravel 为 TinyMCE 中的标签提供 id
- c++ - OLE 自动化 - 任务管理器中的 Ghost Excel 实例
- python - 预测训练模型上新文本输入的标签
- uml - 在活动图中用什么符号表示活动必须在两天内完成?
- json - [未处理的承诺拒绝:SyntaxError: JSON Parse error: Unrecognized token '']