Problem p00087 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
  std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
  string a, str;
  while (getline(cin, str)) {
    stack<double> st;
    stringstream ss;
    ss << str;
    while (ss >> a) {
      double b, c;
      if (a == "+" || a == "-" || a == "*" || a == "/") {
        c = st.top(), st.pop();
        b = st.top(), st.pop();
        if (a == "+")
          st.push(b + c);
        else if (a == "-")
          st.push(b - c);
        else if (a == "*")
          st.push(b * c);
        else
          st.push(b / c);
      } else
        st.push(atof(a.c_str()));
    }
    printf("%.6f\\n", st.top());
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
  std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
  string str;
  while (getline(cin, str)) {
    if (str[0] == '\\0') {
      break;
    }
    stack<double> M;
    stringstream ss(str);
    while (ss >> str) {
      double a1 = 0;
      double a2 = 0;
      if (str[0] == '+') {
        a2 = M.top();
        M.pop();
        a1 = M.top();
        M.pop();
        a1 = a1 + a2;
        M.push(a1);
      } else if (str[0] == '-') {
        a2 = M.top();
        M.pop();
        a1 = M.top();
        M.pop();
        a1 = a1 - a2;
        M.push(a1);
      } else if (str[0] == '*') {
        a2 = M.top();
        M.pop();
        a1 = M.top();
        M.pop();
        a1 = a1 * a2;
        M.push(a1);
      } else if (str[0] == '/') {
        a2 = M.top();
        M.pop();
        a1 = M.top();
        M.pop();
        a1 = a1 / a2;
        M.push(a1);
      } else {
        double a = 0;
        double k = str.size();
        for (int i = 0; i < k; i++) {
          a += (str[i] - '0') * (pow(10.0, k - i - 1));
        }
        M.push(a);
      }
    }
    printf("%.8f\\n", M.top());
  }
  return 0;
}