Why am I getting this strange error?

Error: I get the error "initializer-string for array of chars is too long"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #include <iostream>
#include <cstdlib>
using namespace std;

//To create our map
char map[10][20] = {
        "##################"
        "#                #"
        "#                #"
        "#                #"
        "#                #"
        "#                #"
        "#                #"
        "#                #"
        "#                #"
        "##################"
                   };


//Is the game running? Is a user active
bool game_running = true;

int main()
{

        while(game_running == true)
        {
          system("cls");
          for(int display = 0; display < 10; display++)
                {
                cout << map[display] << endl;
                }
        }

        return 0;
}
I would keep it simple and do something like this personally. Instead of trying to mess around with multidimensional char arrays.

1
2
3
4
5
6
7
8
9
10
11
12
 string map[10] = {
        "##################",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "##################",
                   };
FWIW, OP, you forgot the commas between each row... which is what was causing the error.
Disch, so how should it look
Hi @shamieh,
this is how
should it look but
to be honest i
prefer @James2250's
approach.


Eyenrique-MacBook-Pro:Desktop Eyenrique$ ./error 
##################
#                #
#                #
#                #
#                #
#                #
#                #
#                #
#                #
##################


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//error.cpp
//##

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main(){

char map[10][20] = {
        "##################",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "#                #",
        "##################"
                   };

for(int i=0;i<10;i++){
        for(int j=0;j<20;j++){
                cout<<map[i][j];
                }//end inner for
cout<<endl;
}//end outer for
return 0; //indicates success
}//end main 
Topic archived. No new replies allowed.