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

#include <bits/stdc++.h>

using namespace std;

int main() {
  string str;
  while (getline(cin, str)) {
    stringstream ss;
    ss << str;
    string s;
    stack<long double> data;
    while (ss >> s) {
      if (s == "+") {
        auto a = data.top();
        data.pop();
        auto b = data.top();
        data.pop();
        data.push(b + a);
      } else if (s == "-") {
        auto a = data.top();
        data.pop();
        auto b = data.top();
        data.pop();
        data.push(b - a);
      } else if (s == "*") {
        auto a = data.top();
        data.pop();
        auto b = data.top();
        data.pop();
        data.push(b * a);
      } else if (s == "/") {
        auto a = data.top();
        data.pop();
        auto b = data.top();
        data.pop();
        data.push(b / a);
      } else {
        data.push(atoi(s.c_str()));
      }
    }
    cout << fixed << setprecision(20) << data.top() << endl;
  }
}

Error: -11

Fixed submission:

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
/*
template <typename T>
class UF
{
public:
        void push ( T a )
        {
                M[a] = count;
                V.push_back ( count );
                rank.push_back ( 0 );
                count++;
        }

        void unite ( T a , T b )
        {
                long long int x = find ( M[a] );
                long long int y = find ( M[b] );
                if( x == y )return;
                if( rank[x] < rank[y] )
                {
                        V[x] = y;
                } else
                {
                        V[y] = x;
                        if( rank[x] == rank[y] )rank[x]++;
                }
        }
        bool same ( T a , T b )
        {
                return find ( M[a] ) == find ( M[b] );
        }
        long long int group ()
        {
                set<long long int>S;
                for( long long int i = 0; i < V.size (); i++ )
                {
                        S.insert ( find ( V[i] ) );
                }
                return S.size ();
        }

private:
        vector<long long int>V , rank;
        map < T , long long int>M;
        long long int count = 0;

        long long int find ( long long int x )
        {
                if( V[x] == x )return x;
                else return V[x] = find ( V[x] );
        }
};
*/

int main() {
  string str;
  while (getline(cin, str)) {
    vector<double> data;
    int r = 0;
    bool f = 0;
    for (size_t i = 0; i < str.size(); i++) {
      switch (str[i]) {
      case '+': {
        int b = data.back();
        data.pop_back();
        int a = data.back();
        data.pop_back();
        data.push_back(a + b);
        f = 0;
        break;
      }
      case '*': {
        int b = data.back();
        data.pop_back();
        int a = data.back();
        data.pop_back();
        data.push_back(a * b);
        f = 0;
        break;
      }
      case '-': {
        int b = data.back();
        data.pop_back();
        int a = data.back();
        data.pop_back();
        data.push_back(a - b);
        f = 0;
        break;
      }
      case '/': {
        int b = data.back();
        data.pop_back();
        int a = data.back();
        data.pop_back();
        data.push_back(a / b);
        f = 0;
        break;
      }
      case ' ': {
        if (f) {
          data.push_back(r);
          r = 0;
        }
        break;
      }
      default: {
        r *= 10;
        r += str[i] - '0';
        f = 1;
      }
      }
    }
    cout << fixed << setprecision(8) << data[0] << endl;
  }
}