2015-03-03 160 views
-7

提取整數我有類似:C++:從字符串對象

string s = "Max of 3 and 5"; 

string s = "9 divided by -3"; 

和我需要顯示的表達的結果。

但是,如何從字符串中提取操作數。 在Java中,我可以但我不確定在C++中。

+0

http://stackoverflow.com/questions/27400131/extract-numbers-from-string-regex-c – Anju 2015-03-03 04:44:02

+0

不過,我不希望使用REG EXPS – Boyyett 2015-03-03 04:46:04

+0

@Boyyett嗯,有各種方法可用,例如['Stoi旅館()'](http://en.cppreference.com/w/cpp/string/basic_string/stol) – 2015-03-03 04:46:13

回答

0

爲什麼不使用sscanf?

int a{}; 

int b{}; 

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