-7
提取整数我有类似:C++:从字符串对象
string s = "Max of 3 and 5";
或
string s = "9 divided by -3";
和我需要显示的表达的结果。
但是,如何从字符串中提取操作数。 在Java中,我可以但我不确定在C++中。
提取整数我有类似:C++:从字符串对象
string s = "Max of 3 and 5";
或
string s = "9 divided by -3";
和我需要显示的表达的结果。
但是,如何从字符串中提取操作数。 在Java中,我可以但我不确定在C++中。
为什么不使用sscanf?
int a{};
int b{};
std::sscanf("max of 3 and 5", "max of %d and %d", &a, &b);
http://stackoverflow.com/questions/27400131/extract-numbers-from-string-regex-c – Anju 2015-03-03 04:44:02
不过,我不希望使用REG EXPS – Boyyett 2015-03-03 04:46:04
@Boyyett嗯,有各种方法可用,例如['Stoi旅馆()'](http://en.cppreference.com/w/cpp/string/basic_string/stol) – 2015-03-03 04:46:13