June 2017
Intermediate to advanced
532 pages
12h 59m
English
In the main loop of evaluate_rpn, we take the current string token from the iterator and then see whether it is an operand or not. If the string can be parsed into a double variable, then it is a number, and hence also an operand. We consider everything which is not easily parseable as a number (such as "+", for example) to be an operation.
The naked code skeleton for exactly this task is as follows:
stringstream ss {*it};if (double val; ss >> val) { // It's a number!} else { // It's something else than a number - an operation!}
The stream operator >> tells us if it is a number. First, we wrapped the string into an std::stringstream. Then we use the stringstream object's capability ...
Read now
Unlock full access