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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline double toDouble(string s) {
  double v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch : s) {
    if (ch == delim) {
      if (!item.empty())
        elems.push_back(item);
      item.clear();
    } else {
      item += ch;
    }
  }
  if (!item.empty())
    elems.push_back(item);
  return elems;
}

// debug
//-------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

stack<double> st;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  while (getline(cin, s)) {
    vector<string> str = split(s, ' ');

    for (auto const &v : str) {
      if (v == "+") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(a + b);
        continue;
      } else if (v == "-") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(b - a);
        continue;
      } else if (v == "/") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(b / a);
        continue;
      } else if (v == "*") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(a * b);
        continue;
      }
      st.push(toDouble(v));
    }

    printf("%.6f\\n", st.top());
    st.pop();
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline double toDouble(string s) {
  double v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch : s) {
    if (ch == delim) {
      if (!item.empty())
        elems.push_back(item);
      item.clear();
    } else {
      item += ch;
    }
  }
  if (!item.empty())
    elems.push_back(item);
  return elems;
}

// debug
//-------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

stack<double> st;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (1) {
    if (cin.eof())
      return 0;
    string s;
    getline(cin, s);
    vector<string> str = split(s, ' ');

    for (auto const &v : str) {
      if (v == "+") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(a + b);
        continue;
      } else if (v == "-") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(b - a);
        continue;
      } else if (v == "/") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(b / a);
        continue;
      } else if (v == "*") {
        double a = st.top();
        st.pop();
        double b = st.top();
        st.pop();
        st.push(a * b);
        continue;
      }
      st.push(toDouble(v));
    }

    cout << st.top() << endl;
    st.pop();
  }

  return 0;
}