title: Infix to postfix - Including negative values
body: <p>I'm making a function to convert a infix math-string to postfix.
  This is what I have:</p>
  
  <pre><code>std::string toPostfix(std::string&amp; infixStr, std::string&amp; postfixStr, std::string&amp; first_nr, std::string&amp; second_nr, char oper, char prev_oper) {
  
      //std::cout &lt;&lt; "[" &lt;&lt; infixStr &lt;&lt; "]" &lt;&lt; std::endl;
  
      if (infixStr == "") {
          if (second_nr == "") {
              second_nr = "0";
          }
  
          if (oper == '\0') {
              oper = prev_oper;
  
              if (prev_oper == '-') {
                  second_nr = first_nr;
                  first_nr = "0";
              }
          }
  
  
          postfixStr += first_nr + " " + second_nr + " " + oper;
  
          std::cout &lt;&lt; " end: " &lt;&lt; postfixStr &lt;&lt; std::endl ;
          return postfixStr;
      }
  
  
      char c = infixStr[0];
  
      if (isOperator(c)) {
          ///////////////
          if (postfixStr == "") {
              if (c == '-') {
  
              }
          }
          //////////////////
  
          if (oper != '\0') {
              if (first_nr == "") {
                  if (oper == '-') {
                      /////////////////////////
                  }
              }
  
              postfixStr += first_nr + " " + second_nr + " " + oper + " ";
  
              first_nr = "";
              second_nr = "";
              oper = '\0';
              prev_oper = c;
          } else {
  
              oper = c;
          }
      } else {
          if (oper == '\0') {
              first_nr += c;
          } else {
              second_nr += c;
          }
      }
  
      infixStr = infixStr.erase(0, 1);
      return toPostfix(infixStr, postfixStr, first_nr, second_nr, oper, prev_oper);
  }
  
  </code></pre>
  
  <p>This works in some cases, however for example this input string <code>0+1-5+2</code> the output is <code>0 1 + 5 2 +</code>. The <code>-</code> gets ignored. The correct output should be <code>0 1 + -5 2 +</code> What am I doing wrong? I think I need to differentiate a minus as in operator, and minus as in making a value negative. </p>