Language: C++

using namespace std;

int H, W;
vector<string> S;

char getElement(int h, int w){
    if( h >= 0 && h < H && w >= 0 && w < W ){
        return S[h][w];
    } else {
        return '0';
    }
}

int main(int argc, char const *argv[])
{
    
    cin >> H >> W;
    S.resize(H);
    for (int i = 0; i < H; i++)
    {
        cin >> S[i];
    }
    
    for(int h = 0; h < H; h++){
        string s = "";
        for(int w = 0; w < W; w++){
            if(S[h][w] == '#') {
                s.append("#");
                continue;
            } else {
                int cnt = 0;
                if(getElement(h-1,w) == '#') cnt++;
                if(getElement(h-1,w-1) == '#') cnt++;
                if(getElement(h-1,w+1) == '#') cnt++;
                if(getElement(h,w-1) == '#') cnt++;
                if(getElement(h,w+1) == '#') cnt++;
                if(getElement(h+1,w) == '#') cnt++;
                if(getElement(h+1,w-1) == '#') cnt++;
                if(getElement(h+1,w+1) == '#') cnt++;

                s.append(to_string(cnt));
            }
        }
        cout << s << endl;
    }
    
    return 0;
}



Compiler output:
a.cc:4:1: error: 'vector' does not name a type
    4 | vector<string> S;
      | ^~~~~~
a.cc: In function 'char getElement(int, int)':
a.cc:8:16: error: 'S' was not declared in this scope
    8 |         return S[h][w];
      |                ^
a.cc: In function 'int main(int, const char**)':
a.cc:17:5: error: 'cin' was not declared in this scope
   17 |     cin >> H >> W;
      |     ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:18:5: error: 'S' was not declared in this scope
   18 |     S.resize(H);
      |     ^
a.cc:25:9: error: 'string' was not declared in this scope
   25 |         string s = "";
      |         ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | using namespace std;
a.cc:28:17: error: 's' was not declared in this scope
   28 |                 s.append("#");
      |                 ^
a.cc:41:17: error: 's' was not declared in this scope
   41 |                 s.append(to_string(cnt));
      |                 ^
a.cc:41:26: error: 'to_string' was not declared in this scope
   41 |                 s.append(to_string(cnt));
      |                          ^~~~~~~~~
a.cc:41:26: note: 'std::to_string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
a.cc:44:9: error: 'cout' was not declared in this scope
   44 |         cout << s << endl;
      |         ^~~~
a.cc:44:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:17: error: 's' was not declared in this scope
   44 |         cout << s << endl;
      |                 ^
a.cc:44:22: error: 'endl' was not declared in this scope
   44 |         cout << s << endl;
      |                      ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;