Language: C++

#include <iostream>
using namespace std;

int flag(int h, int w, int H, int W)
{
  int fhw, fh, fw;
  if (h == 0) {
    fh = 10;
  } else if (h != 0 && h != H-1) {
    fh = 20;
  } else {
    fh = 30;
  }
  
  if (w == 0) {
    fw = 1;
  } else if (w != 0 && w != W-1) {
    fh = 2;
  } else {
    fh = 3;
  }
  fhw = fh + fw;
  return fhw;
}


int main()
{
  int H, W;
  cin >> H >> W;
  char ist[55][55];
  char ost[55][55];
  for (int h = 0; h < H; h++) {
    cin.getline(str[h],55);
  }
  
  for (int h = 0; h < H; h++) {
    for (int w = 0;w < W; w++) {
      if (ist[h][w] != '#') {
        int fl = flag (h, w, H, W);
        int bomb = 0;
        switch (fl) {
          case 11:
            if (ist[h+1][w] != '#') bomb++;
            if (ist[h][w+1] != '#') bomb++;
            if (ist[h+1][w+1] != '#') bomb++;
            break;
          case 12:
            if (ist[h][w-1] != '#') bomb++;
            if (ist[h][w+1] != '#') bomb++;
            if (ist[h+1][w-1] != '#') bomb++;
            if (ist[h+1][w] != '#') bomb++;
            if (ist[h+1][w+1] != '#') bomb++;
            break;
          case 13:
            if (ist[h][w-1] != '#') bomb++;
            if (ist[h-1][w-1] != '#') bomb++;
            if (ist[h-1][w] != '#') bomb++;
            break;
          case 21:
            if (ist[h-1][w] != '#') bomb++;
            if (ist[h+1][w] != '#') bomb++;
            if (ist[h-1][w+1] != '#') bomb++;
            if (ist[h][w+1] != '#') bomb++;
            if (ist[h-1][w+1] != '#') bomb++;
            break;
          case 22:
            if (ist[h-1][w-1] != '#') bomb++;
            if (ist[h-1][w] != '#') bomb++;
            if (ist[h-1][w+] != '#') bomb++;
            if (ist[h][w-1] != '#') bomb++;
            if (ist[h][w+1] != '#') bomb++;
            if (ist[h+1][w-1] != '#') bomb++;
            if (ist[h+1][w] != '#') bomb++;
            if (ist[h+1][w+1] != '#') bomb++;
            break;
          case 23:
            if (ist[h-1][w-1] != '#') bomb++;
            if (ist[h-1][w] != '#') bomb++;
            if (ist[h][w-1] != '#') bomb++;
            if (ist[h+1][w-1] != '#') bomb++;
            if (ist[h+1][w] != '#') bomb++;
            break;
          case 31:
            if (ist[h-1][w] != '#') bomb++;
            if (ist[h-1][w+] != '#') bomb++;
            if (ist[h][w+1] != '#') bomb++;
            break;
          case 32:
            if (ist[h-1][w-1] != '#') bomb++;
            if (ist[h-1][w] != '#') bomb++;
            if (ist[h-1][w+] != '#') bomb++;
            if (ist[h][w-1] != '#') bomb++;
            if (ist[h][w+1] != '#') bomb++;
            break;
          case 33:
            if (ist[h-1][w-1] != '#') bomb++;
            if (ist[h-1][w] != '#') bomb++;
            if (ist[h][w-1] != '#') bomb++;
            break;
          ost[h][w] = bomb;
        }
      } else {
        ost [h][w] = '#';
      }
    }
  }
  for (int h = 0; h < H; h++) {
   for (int w = 0;w < W; w++) {
     cout << ost[h][w];
   }
    endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:17: error: 'str' was not declared in this scope; did you mean 'std'?
   34 |     cin.getline(str[h],55);
      |                 ^~~
      |                 std
a.cc:70:28: error: expected primary-expression before ']' token
   70 |             if (ist[h-1][w+] != '#') bomb++;
      |                            ^
a.cc:86:28: error: expected primary-expression before ']' token
   86 |             if (ist[h-1][w+] != '#') bomb++;
      |                            ^
a.cc:92:28: error: expected primary-expression before ']' token
   92 |             if (ist[h-1][w+] != '#') bomb++;
      |                            ^
a.cc:112:9: error: statement cannot resolve address of overloaded function
  112 |     endl;
      |         ^