title: terminate called after throwing an instance of 'std::out_of_range'
body: <p><strong>terminate called after throwing an instance of 'std::out_of_range'</strong></p>
  
  <p><strong>what(): basic_string::replace</strong></p>
  
  <p>Hi, guys. I was wondering if you could help me figure out the error in bold. I'm making a program that interprets addition and multiplication expressions (with parentheses allowed). It uses recursion but no special data structures. Anyways, I don't believe I need to post the entire program. It's compiling and I was testing it with the expression "5*3" which should return the string "15". For some reason, I'm getting an out-of-bounds error when I use the replace() function for a string. I was wondering if you have any idea why based on the following snippet of code. Any help greatly appreciated. </p>
  
  <pre><code>size_t firstast = eq.find_first_of('*'); // position of first asterisk 
      if (firstast != std::string::npos) {
          // Set num1 and num2 equal to the respective numbers to the left and right of the asterisk:
          std::string num1, num2; 
          size_t num1begin(firstast), num2end(firstast);
          while (isdigit(eq[--num1begin])) 
              num1.insert(0, 1, eq[num1begin]);
          while (isdigit(eq[++num2end]))
              num2.push_back(eq[num2end]);
          // Replace the space of the multiplication equation num1*num2 with its evaluation:
          eq.replace(num1begin, num2end - num1begin + 1, multStrs(num1, num2));
          evaluate_equation(eq);
      }
  </code></pre>