Language: C++

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

int main(){
  int H, W;
  cin >> H >> W;
  string S;
  
  for(int i = 0; i < H; i++){
    cin >> S[i];
  }//Sの配置完了
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(S[i][j] == '.'){
        int x = 0;
        if((0<=i-1)&&(i-1<=H-1)&&(0<=j-1)&&(j-1<=W-1)){
          if(S[i-1][j-1]=='#'){
          x++;
          }
        }
        if((0<=i-1)&&(i-1<=H-1)&&(0<=j)&&(j<=W-1)){
          if(S[i-1][j]=='#'){
          x++;
          }
        }
        if((0<=i-1)&&(i-1<=H-1)&&(0<=j+1)&&(j+1<=W-1)){
          if(S[i-1][j+1]=='#'){
          x++;
          }
        }
        if((0<=i)&&(i<=H-1)&&(0<=j-1)&&(j-1<=W-1)){
          if(S[i][j-1]=='#'){
          x++;
          }
        }
        if((0<=i)&&(i<=H-1)&&(0<=j+1)&&(j+1<=W-1)){
          if(S[i][j+1]=='#'){
          x++;
          }
        }
        if((0<=i+1)&&(i+1<=H-1)&&(0<=j-1)&&(j-1<=W-1)){
          if(S[i+1][j-1]=='#'){
          x++;
          }
        }
          if((0<=i+1)&&(i+1<=H-1)&&(0<=j)&&(j<=W-1)){
            if(S[i+1][j]=='#'){
          x++;
            }
        }
          if((0<=i+1)&&(i+1<=H-1)&&(0<=j+1)&&(j+1<=W-1)){
            if(S[i+1][j+1]=='#'){
          x++;
            }
        }
        S[i][j]='0'+x;
      }
    }
  }
  for(int i = 0;i<H; i++)
  cout << S[i] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:14: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   14 |       if(S[i][j] == '.'){
      |              ^
a.cc:17:20: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   17 |           if(S[i-1][j-1]=='#'){
      |                    ^
a.cc:22:20: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   22 |           if(S[i-1][j]=='#'){
      |                    ^
a.cc:27:20: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   27 |           if(S[i-1][j+1]=='#'){
      |                    ^
a.cc:32:18: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   32 |           if(S[i][j-1]=='#'){
      |                  ^
a.cc:37:18: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   37 |           if(S[i][j+1]=='#'){
      |                  ^
a.cc:42:20: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   42 |           if(S[i+1][j-1]=='#'){
      |                    ^
a.cc:47:22: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   47 |             if(S[i+1][j]=='#'){
      |                      ^
a.cc:52:22: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   52 |             if(S[i+1][j+1]=='#'){
      |                      ^
a.cc:56:13: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}[int]' for array subscript
   56 |         S[i][j]='0'+x;
      |             ^