How to do it...

In this section, we will read a mathematical expression in RPN from the standard input, and then feed it into a function that evaluates it. In the end, we print the numeric result back to the user.

  1. We will use a lot of helpers from the STL, so there are a few includes:
      #include <iostream>      #include <stack>      #include <iterator>      #include <map>      #include <sstream>      #include <cassert>      #include <vector>      #include <stdexcept>      #include <cmath>
  1. And we do also declare that we are using namespace std in order to spare us some typing.
      using namespace std;
  1. Then, we immediately start implementing our RPN parser. It will accept an iterator pair, which denotes the beginning and end of a mathematical expression in string form, which will ...

Get C++17 STL Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.