Language: C++

#include <bits/stdc++.h>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  
  string S0, S1;
  cin >> S0 >> S1;
    
  for (int j = 0; j < W; j++) {
    if (S0.at(j)=='.') {
      int count=0;
      string countre;
      if (S0.at(j-1)=='#')
        count++;
      if (S0.at(j+1)=='#')
        count++;
      if (S1.at(j-1)=='#')
        count++;
      if (S1.at(j)=='#')
        count++;
      if (S1.at(j+1)=='#')
        count++;
      countre = to_string(count);
      S0.at(j)=countre;
    }
  }
  cout << S0 << endl; //0行目終了
  
  string Sb, Sn, Sa;
  
  Sb=S0;
  Sn=S1;
  cin >> Sa; //2列目を入力
  
  for (int i = 0; i < H-3; i++) {
    for (int j = 0; j < W; j++) {
      if (Sn.at(j)=='.') {
        int count=0;
        string countre;
        if (Sb.at(j-1)=='#')
          count++;
        if (Sb.at(j)=='#')
          count++;
        if (Sb.at(j+1)=='#')
          count++;
        if (Sn.at(j-1)=='#')
          count++;
        if (Sn.at(j+1)=='#')
          count++;
        if (Sa.at(j-1)=='#')
          count++;
        if (Sa.at(j)=='#')
          count++;
        if (Sa.at(j+1)=='#')
          count++;
        countre = to_string(count);
        Sn.at(j)=countre;
      }
    }
    cout << Sn << endl;
    Sb=Sn;
    Sn=Sa;
    string S;
    cin >> S;
    Sa=S;
  }                                //H-2行まで終了
  
      for (int j = 0; j < W; j++) {
      if (Sn.at(j)=='.') {
        int count=0;
        string countre;
        if (Sb.at(j-1)=='#')
          count++;
        if (Sb.at(j)=='#')
          count++;
        if (Sb.at(j+1)=='#')
          count++;
        if (Sn.at(j-1)=='#')
          count++;
        if (Sn.at(j+1)=='#')
          count++;
        if (Sa.at(j-1)=='#')
          count++;
        if (Sa.at(j)=='#')
          count++;
        if (Sa.at(j+1)=='#')
          count++;
        countre = to_string(count);
        Sn.at(j)=countre;
      }
    }
    cout << Sn << endl;
    Sb=Sn;
    Sn=Sa;
  
  for (int j = 0; j < W; j++) {
    if (Sn.at(j)=='.') {
      int count=0;
      string countre;
      if (Sn.at(j-1)=='#')
        count++;
      if (Sn.at(j+1)=='#')
        count++;
      if (Sb.at(j-1)=='#')
        count++;
      if (Sb.at(j)=='#')
        count++;
      if (Sb.at(j+1)=='#')
        count++;
      countre = to_string(count);
      Sn.at(j)=countre;
    }
  }
  cout << Sn << endl; //H行目終了
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:16: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} in assignment
   28 |       S0.at(j)=countre;
      |                ^~~~~~~
      |                |
      |                std::string {aka std::__cxx11::basic_string<char>}
a.cc:61:18: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} in assignment
   61 |         Sn.at(j)=countre;
      |                  ^~~~~~~
      |                  |
      |                  std::string {aka std::__cxx11::basic_string<char>}
a.cc:93:18: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} in assignment
   93 |         Sn.at(j)=countre;
      |                  ^~~~~~~
      |                  |
      |                  std::string {aka std::__cxx11::basic_string<char>}
a.cc:115:16: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} in assignment
  115 |       Sn.at(j)=countre;
      |                ^~~~~~~
      |                |
      |                std::string {aka std::__cxx11::basic_string<char>}