Language: C++

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

int main(){
  int n;
  string s1,s2,ans;
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> s1;
    cin >> s2;
    int m = max(s1.size(),s2.size());
    while(m>s1.size()) '0' + s1;
    while(m>s2.size()) '0' + s2;

    int carry = 0;
    for(int j=m-1; m>=0; m--){
      char ch = ((s1[m]-'0') + (s2[m]-'0') + carry)%10 + '0';
      carry = ((s1[m]-'0') + (s2[m]-'0') + carry)/10;
      ans.append(ch);
    }
    if(carry) ans.append(carry+'0');
    reverse(ans.begin(),ans.end());

    //頭の0を削除していく
    while(ans.size()>1 && ans[0] == '0') ans.erase(ans.begin());
    if(ans.size() > 80) cout << 'overflow' << endl;
    cout << ans << endl;
  }
  return 0;
}

Compiler output:
a.cc:29:33: warning: multi-character literal with 8 characters exceeds 'int' size of 4 bytes
   29 |     if(ans.size() > 80) cout << 'overflow' << endl;
      |                                 ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:15:30: warning: ignoring return value of 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]', declared with attribute 'nodiscard' [-Wunused-result]
   15 |     while(m>s1.size()) '0' + s1;
      |                              ^~
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:3635:5: note: declared here
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
a.cc:16:30: warning: ignoring return value of 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]', declared with attribute 'nodiscard' [-Wunused-result]
   16 |     while(m>s2.size()) '0' + s2;
      |                              ^~
/usr/include/c++/14/bits/basic_string.h:3635:5: note: declared here
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
a.cc:22:17: error: no matching function for call to 'std::__cxx11::basic_string<char>::append(char&)'
   22 |       ans.append(ch);
      |       ~~~~~~~~~~^~~~
/usr/include/c++/14/bits/basic_string.h:1480:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' (near match)
 1480 |       append(const _CharT* __s)
      |       ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1480:7: note:   conversion of argument 1 would be ill-formed:
a.cc:22:18: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
   22 |       ans.append(ch);
      |                  ^~
      |                  |
      |                  char
/usr/include/c++/14/bits/basic_string.h:1529:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1529 |         append(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1529:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:1541:9: note: candidate: 'template<class _Tp> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_If_sv<_Tp, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1541 |         append(const _Tp& __svt)
      |         ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1541:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/type_traits: In substitution of 'template<bool _Cond, class _Tp> using std::enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = std::__cxx11::basic_string<char>&]':
/usr/include/c++/14/bits/basic_string.h:149:8:   required by substitution of 'template<class _CharT, class _Traits, class _Alloc> template<class _Tp, class _Res> using std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_If_sv = std::enable_if_t<((bool)std::__and_<std::is_convertible<const _Tp&, std::basic_string_view<_CharT, _Traits> >, std::__not_<std::is_convertible<const _Tp*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>*> >, std::__not_<std::is_convertible<const _Tp&, const _CharT*> > >::value), _Res> [with _Tp = char; _Res = std::__cxx11::basic_string<char>&; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
  149 |         using _If_sv = enable_if_t<
      |               ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1541:9:   required by substitution of 'template<class _Tp> std::__cxx11::basic_string<char>::_If_sv<_Tp, std::__cxx11::basic_string<char>&> std::__cxx11::basic_string<char>::append(const _Tp&) [with _Tp = char]'
 1541 |         append(const _Tp& __svt)
      |         ^~~~~~
a.cc:22:17:   required from here
   22 |       ans.append(ch);
      |       ~~~~~~~~~~^~~~
/usr/include/c++/14/type_traits:2711:11: error: no type named 'type' in 'struct std::enable_if<false, std::__cxx11::basic_string<char>&>'
 2711 |     using enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:1557:9: note: candidate: 'template<class _Tp> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_If_sv<_Tp, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const _Tp&, size_type, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1557 |         append(const _Tp& __svt, size_type __pos, size_type __n = npos)
      |         ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1557:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:1435:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1435 |       append(const basic_string& __str)
      |       ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1435:34: note:   no known conversion for argument 1 from 'char' to 'const std::__cxx11::basic_string<char>&'
 1435 |       append(const basic_string& __str)
      |              ~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:1453:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, size_type, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
 1453 |       append(const basic_string& __str, size_type __pos, size_type __n = npos)
      |       ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1453:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:1466:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
 1466 |       append(const _CharT* __s, size_type __n)
      |       ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1466:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:1498:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(size_type, _CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
 1498 |       append(size_type __n, _CharT __c)
      |       ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1498:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:1509:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(std::initializer_list<_Tp>) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1509 |       append(initializer_list<_CharT> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1509:39: note:   no known conversion for argument 1 from 'char' to 'std::initializer_list<char>'
 1509 |       append(initializer_list<_CharT> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:24:25: error: no matching function for call to 'std::__cxx11::basic_string<char>::append(int)'
   24 |     if(carry) ans.append(carry+'0');
      |               ~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:1480:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' (near match)
 1480 |       append(const _CharT* __s)
      |       ^~~~~~
/usr/include/c++/14/bits/basic_string.h:1480:7: note:   conversion of argument 1 would be ill-formed:
a.cc:24:31: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
   24 |     if(carry) ans.append(carry+'0');
      |                          ~~~~~^~~~
      |                               |
      |                               int
/usr/include/c++/14/bits/basic_string.h:1529:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1529 |         append(_InputIterator __first, _InputIterator __last)