Language: C++

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string s;
    cin >> s;
    string ans = "";

    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '0') {
            ans.push_back('0');
        }
        else if(s[i] == '1') {
            ans.push_back('1');
        }
        else {
            if(ans == "") {
                continue;
            }
            else {
                ans.erase(ans.end(), 1);
            }
        }
    }

    cout << ans;
    
    cout << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:26: error: no matching function for call to 'std::__cxx11::basic_string<char>::erase(std::__cxx11::basic_string<char>::iterator, int)'
   23 |                 ans.erase(ans.end(), 1);
      |                 ~~~~~~~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:2114:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(size_type, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
 2114 |       erase(size_type __pos = 0, size_type __n = npos)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2114:23: note:   no known conversion for argument 1 from 'std::__cxx11::basic_string<char>::iterator' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 2114 |       erase(size_type __pos = 0, size_type __n = npos)
      |             ~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:2134:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(__const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; iterator = std::__cxx11::basic_string<char>::iterator; __const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 2134 |       erase(__const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2134:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/basic_string.h:2154:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(__const_iterator, __const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; iterator = std::__cxx11::basic_string<char>::iterator; __const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 2154 |       erase(__const_iterator __first, __const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2154:56: note:   no known conversion for argument 2 from 'int' to 'std::__cxx11::basic_string<char>::__const_iterator' {aka 'std::__cxx11::basic_string<char>::const_iterator'}
 2154 |       erase(__const_iterator __first, __const_iterator __last)
      |                                       ~~~~~~~~~~~~~~~~~^~~~~~