Language: C++

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

int main() {
  int N, W;
  string all = "";
  
  string k;
  for (int i=0; i<N; i++) {
    cin >> k;
    all += k;
  }
  
  for (int i=0; i<N*W, i++) {
    // 改行処理
    if (i != 0 && i%W == 0)
      cout << endl;
    // 自身が幕弾の時
    if (all.at(i) == "#") 
      cout << "#";
    // 爆弾でない時
    else {
      int count = 0;
      bool checker_1 = false;
      bool checker_2 = false;
      // 上がある
      if (W < i) {
        if (all.at(i-W) == "#")
          count++;
        checker_1 = true;
      }
      // 下がある
      if (i < W*(N=1)) {
        if (all.at(i+W) == "#")
          count++;
        checker_2 = true;
      }
      // 左がある
      if (i%W != 0) {
        if (all.at(i-1) == "#")
          count++;
        // 左上がある
        if (checker_1) {
          if (all.at(i-W-1) == "#")
            count++;
        }
        // 左下がある
        if (checker_2) {
          if (all.at(i+W-1) == "#")
            count++;
        }
      }
      // 右がある
      if (i%W != W-1) {
        if (all.at(i+1) == "#")
          count++;
        // 右上がある
        if (checker_1) {
          if (all.at(i-W+1) == "#")
            count++;
        }
        // 右下がある
        if (checker_2) {
          if (all.at(i+W+1) == "#")
            count++;
        }
      }
      cout << count;
    }
  }
    
      
      
    

Compiler output:
a.cc: In function 'int main()':
a.cc:14:27: error: expected ';' before ')' token
   14 |   for (int i=0; i<N*W, i++) {
      |                           ^
      |                           ;
a.cc:19:19: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   19 |     if (all.at(i) == "#")
      |         ~~~~~~~~~~^~~~~~
a.cc:28:25: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   28 |         if (all.at(i-W) == "#")
      |             ~~~~~~~~~~~~^~~~~~
a.cc:34:25: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   34 |         if (all.at(i+W) == "#")
      |             ~~~~~~~~~~~~^~~~~~
a.cc:40:25: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   40 |         if (all.at(i-1) == "#")
      |             ~~~~~~~~~~~~^~~~~~
a.cc:44:29: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   44 |           if (all.at(i-W-1) == "#")
      |               ~~~~~~~~~~~~~~^~~~~~
a.cc:49:29: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   49 |           if (all.at(i+W-1) == "#")
      |               ~~~~~~~~~~~~~~^~~~~~
a.cc:55:25: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   55 |         if (all.at(i+1) == "#")
      |             ~~~~~~~~~~~~^~~~~~
a.cc:59:29: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   59 |           if (all.at(i-W+1) == "#")
      |               ~~~~~~~~~~~~~~^~~~~~
a.cc:64:29: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   64 |           if (all.at(i+W+1) == "#")
      |               ~~~~~~~~~~~~~~^~~~~~
a.cc:70:4: error: expected '}' at end of input
   70 |   }
      |    ^
a.cc:4:12: note: to match this '{'
    4 | int main() {
      |            ^