Language: C++

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

int main() {
  int a,b,i,j,e;
  char d;
  cin>>a>>b;
  vector<string>c(a);
  for(i=0;i<a;i++){
    cin>>c.at(i);
  }
  for(i=0;i<a;i++){
    for(j=0;i<b;i++){
      d=(c.at(i)).at(j);
      if(d!=#){
        e=0
        if(i==0&&j==0){
          if(((c.at(i)).at(j+1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j))=='#')
            e+=1;
          if(((c.at(i+1)).at(j+1))=='#')
            e+=1;
        }else if(i==0&&j>0&&j<(b-1)){
          if(((c.at(i)).at(j-1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j-1))=='#')
            e+=1;
          if(((c.at(i)).at(j+1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j))=='#')
            e+=1;
          if(((c.at(i+1)).at(j+1))=='#')
            e+=1;
        }else if(i==0&&j==(b-1)){
          if(((c.at(i)).at(j-1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j-1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j))=='#')
            e+=1;
        }else if(i>0&&i<(a-1)&&j==1){
          if(((c.at(i-1)).at(j))=='#')
            e+=1;
          if(((c.at(i-1)).at(j+1))=='#')
            e+=1;
          if(((c.at(i)).at(j+1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j))=='#')
            e+=1;
          if(((c.at(i+1)).at(j+1))=='#')
            e+=1;
        }else if(i>0&&i<(a-1)&&j>0&&j<(b-1)){
          if(((c.at(i-1)).at(j))=='#')
            e+=1;
          if(((c.at(i-1)).at(j+1))=='#')
            e+=1;
          if(((c.at(i)).at(j+1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j))=='#')
            e+=1;
          if(((c.at(i+1)).at(j+1))=='#')
            e+=1;
          if(((c.at(i-1)).at(j-1))=='#')
            e+=1;
          if(((c.at(i)).at(j-1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j-1))=='#')
            e+=1;
        }else if(i>0&&i<(a-1)&&j==(b-1)){
          if(((c.at(i-1)).at(j))=='#')
            e+=1;
          if(((c.at(i-1)).at(j-1))=='#')
            e+=1;
          if(((c.at(i)).at(j-1))=='#')
            e+=1;
          if(((c.at(i-1)).at(j))=='#')
            e+=1;
          if(((c.at(i+1)).at(j-1))=='#')
            e+=1;
        }else if(i==(a-1)&&j==1){
          if(((c.at(i-1)).at(j+1))=='#')
            e+=1;
          if(((c.at(i-1)).at(j))=='#')
            e+=1;
          if(((c.at(i)).at(j+1))=='#')
            e+=1;
        }else if(i==(a-1)&&j>1&&j<(b-1)){
          if(((c.at(i-1)).at(j+1))=='#')
            e+=1;
          if(((c.at(i-1)).at(j))=='#')
            e+=1;
          if(((c.at(i)).at(j+1))=='#')
            e+=1;
          if(((c.at(i-1)).at(j-1))=='#')
            e+=1;
          if(((c.at(i)).at(j-1))=='#')
            e+=1;
        }else if(i==(a-1)&&j==(b-1)){
          if(((c.at(i)).at(j-1))=='#')
            e+=1;
          if(((c.at(i-1)).at(j-1))=='#')
            e+=1;
          if(((c.at(i+1)).at(j))=='#')
            e+=1;
        }
        cout<<e;
      }else{
        cout<<'#';
      }
    }
    cout<<endl;
  }
}


Compiler output:
a.cc:15:13: error: stray '#' in program
   15 |       if(d!=#){
      |             ^
a.cc: In function 'int main()':
a.cc:15:14: error: expected primary-expression before ')' token
   15 |       if(d!=#){
      |              ^
a.cc:16:12: error: expected ';' before 'if'
   16 |         e=0
      |            ^
      |            ;
   17 |         if(i==0&&j==0){
      |         ~~  
a.cc:24:10: error: expected '}' before 'else'
   24 |         }else if(i==0&&j>0&&j<(b-1)){
      |          ^~~~
a.cc:15:15: note: to match this '{'
   15 |       if(d!=#){
      |               ^
a.cc:108:8: error: 'else' without a previous 'if'
  108 |       }else{
      |        ^~~~
a.cc: At global scope:
a.cc:114:1: error: expected declaration before '}' token
  114 | }
      | ^