Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int lli;
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define endl "\n"
#define sortin sort(arr.begin(), arr.end())
#define inputArray                                                             \
  for (int i{}; i < n; i++) {                                                  \
    cin >> arr[i];                                                             \
  }
#define inputArray1                                                            \
  for (int i{}; i < m; i++) {                                                  \
    cin >> arr1[i];                                                            \
  }
#define intloop for (int i{}; i < n; i++)
#define intloopminus for (int i{}; i < n - 1; i++)
#define strloop for (int i{}; i < str.length(); i++)
#define N                                                                      \
  int n;                                                                       \
  cin >> n
#define strlen str.length()
#define InputStr                                                               \
  string str;                                                                  \
  cin >> str
#define twoinputs                                                              \
  int n, k;                                                                    \
  cin >> n >> k
#define T                                                                      \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  InputStr;
  string str1 = "";
  for (int i{}; i < str.length(); i++) {
    if (str[0] == 'B') {
      continue;
    } else if (str[i] == '1' || str[i] == '0') {
      str1.pb(str[i]);
    } else if (str[i] == 'B') {
      str1.pop_back();
    }
  }
  cout << str1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long int lli;
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define endl "\n"
#define sortin sort(arr.begin(), arr.end())
#define inputArray                                                             \
  for (int i{}; i < n; i++) {                                                  \
    cin >> arr[i];                                                             \
  }
#define inputArray1                                                            \
  for (int i{}; i < m; i++) {                                                  \
    cin >> arr1[i];                                                            \
  }
#define intloop for (int i{}; i < n; i++)
#define intloopminus for (int i{}; i < n - 1; i++)
#define strloop for (int i{}; i < str.length(); i++)
#define N                                                                      \
  int n;                                                                       \
  cin >> n
#define strlen str.length()
#define InputStr                                                               \
  string str;                                                                  \
  cin >> str
#define twoinputs                                                              \
  int n, k;                                                                    \
  cin >> n >> k
#define T                                                                      \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  InputStr;
  string str1 = "";
  for (int i{}; i < str.length(); i++) {
    if (str[i] == 'B' && str1.empty()) {
      continue;
    } else if (str[i] == '1' || str[i] == '0') {
      str1.pb(str[i]);
    } else if (str[i] == 'B') {
      str1.pop_back();
    }
  }
  cout << str1 << endl;
}