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

// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip> // 10????????? cout << setprecision(10) << double;
#include <iostream>
#include <locale>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int>> MuMAPIC;
typedef vector<pair<int, int>> VPII;
typedef multimap<int, string, greater<int>> MuMIS;

#define MP make_pair
#define FAST_IO                                                                \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
// for gcc (???test)
//  #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin();
//  it!=(c).end(); ++it)
// for Visual Studio
#define foreach_it(type, it, c)                                                \\
  for (type::iterator it = c.begin(), c_end = c.end(); it != c_end; ++it)
// for Debug.
#define DUMP_VVI(b)                                                            \\
  FOR(i, 0, b.size()) {                                                        \\
    FOR(j, 0, b[i].size()) printf("%d ", b[i][j]);                             \\
    puts("");                                                                  \\
  }
#define D_OUT(str, value)                                                      \\
  if (dbgF) {                                                                  \\
    cout << str << " : " << value << endl;                                     \\
  }
// ??\\??????push_back(d)???array[d]???????????????1?????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template <class T> T IN() {
  T d;
  cin >> d;
  return d;
}
// ?????§??¬?´???°???Greatest Common Divisor???
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; }
// ????°???¬?????°???Least Common Multiple???
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

// ------------------- include, typedef, define END. -------------------

int main() {
  FAST_IO;
  // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
  bool dbgF = true;

  //??????????????????????????????.
  int a, b, n;
  while (cin >> a >> b >> n) {
    double temp = (double)a / b;
    double seisuubu;
    double shosuubu = modf(temp, &seisuubu);

    // string ?????????
    string str_shoshuubu;
    stringstream ss;
    ss << setprecision(12) << shosuubu;
    ss >> str_shoshuubu;
    // cout<< str_shoshuubu << " , ";

    // ?°???°?¬¬i????????????
    int ans = 0;
    FOR(i, 0, n) {
      if ((i + 2) >= str_shoshuubu.length())
        ans += 0;
      else
        ans += str_shoshuubu.at(i + 2) - '0';
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip> // 10????????? cout << setprecision(10) << double;
#include <iostream>
#include <locale>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int>> MuMAPIC;
typedef vector<pair<int, int>> VPII;
typedef multimap<int, string, greater<int>> MuMIS;

#define MP make_pair
#define FAST_IO                                                                \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
// for gcc (???test)
//  #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin();
//  it!=(c).end(); ++it)
// for Visual Studio
#define foreach_it(type, it, c)                                                \\
  for (type::iterator it = c.begin(), c_end = c.end(); it != c_end; ++it)
// for Debug.
#define DUMP_VVI(b)                                                            \\
  FOR(i, 0, b.size()) {                                                        \\
    FOR(j, 0, b[i].size()) printf("%d ", b[i][j]);                             \\
    puts("");                                                                  \\
  }
#define D_OUT(str, value)                                                      \\
  if (dbgF) {                                                                  \\
    cout << str << " : " << value << endl;                                     \\
  }
// ??\\??????push_back(d)???array[d]???????????????1?????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template <class T> T IN() {
  T d;
  cin >> d;
  return d;
}
// ?????§??¬?´???°???Greatest Common Divisor???
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; }
// ????°???¬?????°???Least Common Multiple???
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

// ------------------- include, typedef, define END. -------------------

int main() {
  FAST_IO;
  // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
  bool dbgF = true;

  //??????????????????????????????.
  int a, b, n;
  while (cin >> a >> b >> n) {
    double temp = (double)a / b;
    double seisuubu;
    double shosuubu = modf(temp, &seisuubu);

    // string ?????????
    string str_shoshuubu;
    stringstream ss;
    ss << setprecision(12) << shosuubu;
    ss >> str_shoshuubu;
    str_shoshuubu += "0000000000";
    // cout<< str_shoshuubu << " , ";

    // ?°???°?¬¬i????????????
    int ans = 0;
    FOR(i, 0, n) { ans += str_shoshuubu.at(i + 2) - '0'; }
    cout << ans << endl;
  }
  return 0;
}