【问题标题】:C++: Extracting integers from string objectC++:从字符串对象中提取整数
【发布时间】:2015-03-03 04:33:59
【问题描述】:

我有类似的东西:

string s = "Max of 3 and 5";

string s = "9 divided by -3";

我需要显示表达式的结果。

但是,我如何从字符串中提取操作数。 在 Java 中,我可以,但在 C++ 中我不确定。

【问题讨论】:

标签: c++


【解决方案1】:

为什么不使用 sscanf?

int a{};

int b{};

std::sscanf("max of 3 and 5", "max of %d and %d", &a, &b);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 2015-08-26
    • 2021-05-22
    相关资源
    最近更新 更多