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

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  map<char, string> table1;
  map<string, char> table2;
  table1[' '] = "101";
  table1['\\''] = "000000";
  table1[','] = "000011";
  table1['-'] = "10010001";
  table1['.'] = "010001";
  table1['?'] = "000001";
  table1['A'] = "100101";
  table1['B'] = "10011010";
  table1['C'] = "0101";
  table1['D'] = "0001";
  table1['E'] = "110";
  table1['F'] = "01001";
  table1['G'] = "10011011";
  table1['H'] = "010000";
  table1['I'] = "0111";
  table1['J'] = "10011000";
  table1['K'] = "0110";
  table1['L'] = "00100";
  table1['M'] = "10011001";
  table1['N'] = "10011110";
  table1['O'] = "00101";
  table1['P'] = "111";
  table1['Q'] = "10011111";
  table1['R'] = "1000";
  table1['S'] = "00110";
  table1['T'] = "00111";
  table1['U'] = "10011100";
  table1['V'] = "10011101";
  table1['W'] = "000010";
  table1['X'] = "10010010";
  table1['Y'] = "10010011";
  table1['Z'] = "10010000";

  table2["00000"] = 'A';
  table2["00001"] = 'B';
  table2["00010"] = 'C';
  table2["00011"] = 'D';
  table2["00100"] = 'E';
  table2["00101"] = 'F';
  table2["00110"] = 'G';
  table2["00111"] = 'H';
  table2["01000"] = 'I';
  table2["01001"] = 'J';
  table2["01010"] = 'K';
  table2["01011"] = 'L';
  table2["01100"] = 'M';
  table2["01101"] = 'N';
  table2["01110"] = 'O';
  table2["01111"] = 'P';
  table2["10000"] = 'Q';
  table2["10001"] = 'R';
  table2["10010"] = 'S';
  table2["10011"] = 'T';
  table2["10100"] = 'U';
  table2["10101"] = 'V';
  table2["10110"] = 'W';
  table2["10111"] = 'X';
  table2["11000"] = 'Y';
  table2["11001"] = 'Z';
  table2["11010"] = ' ';
  table2["11011"] = '.';
  table2["11100"] = ',';
  table2["11101"] = '-';
  table2["11110"] = '\\'';
  table2["11111"] = '?';

  string strIn;
  string strOut;
  string code;
  int codelen;

  while (getline(cin, strIn)) {
    code = "";
    strOut = "";
    for (int i = 0, l = strIn.length(); i < l; ++i) {
      code += table1[strIn[i]];
    }

    if (codelen = code.length() % 5) {
      for (int i = 0; i < 5 - codelen; ++i)
        code += "0";
    }

    for (int i = 0, len = code.length() / 5; i < len; ++i) {
      cout << table2[code.substr(i * 5, 5)];
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#define CASE(c, s)                                                             \\
  case c:                                                                      \\
    return s
using namespace std;

string f(char c) {
  switch (c) {
    CASE(' ', "101");
    CASE('\\'', "000000");
    CASE(',', "000011");
    CASE('-', "10010001");
    CASE('.', "010001");
    CASE('?', "000001");
    CASE('A', "100101");
    CASE('B', "10011010");
    CASE('C', "0101");
    CASE('D', "0001");
    CASE('E', "110");
    CASE('F', "01001");
    CASE('G', "10011011");
    CASE('H', "010000");
    CASE('I', "0111");
    CASE('J', "10011000");
    CASE('K', "0110");
    CASE('L', "00100");
    CASE('M', "10011001");
    CASE('N', "10011110");
    CASE('O', "00101");
    CASE('P', "111");
    CASE('Q', "10011111");
    CASE('R', "1000");
    CASE('S', "00110");
    CASE('T', "00111");
    CASE('U', "10011100");
    CASE('V', "10011101");
    CASE('W', "000010");
    CASE('X', "10010010");
    CASE('Y', "10010011");
    CASE('Z', "10010000");
  default:
    return "";
  }
}

int bitodec(string s) {
  int sum = 0;
  for (unsigned int i = 0; i < s.length(); ++i) {
    sum *= 2;
    sum += (s[i] - '0');
  }
  return sum;
}

char g(string s) {
  char c[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-\\'?";
  return c[bitodec(s)];
}

int main() {
  string s, r;
  int i;

  while (getline(cin, s)) {
    i = 0;
    r = "";

    while (s[i] != '\\0') {
      r += f(s[i]);
      ++i;
    }

    if (i % 5)
      for (int j = 4 - (i % 5); --j;)
        r += "0";

    for (unsigned int j = 0; j < r.length(); j += 5)
      cout << g(r.substr(j, 5));
    cout << endl;
  }
  return 0;
}