Jul 24, 2018 at 11:39am
Hi, I'm new to c++. How can I create a simple grid map using a 2D array, in C++?
Like below illustration as an EXAMPLE:
1 2 3 4 5 6 7 8 9 10
|
# # # # # #
5 # 1 #
4 # #
3 # 1 #
2 # #
1 # #
0 # # # # # #
0 1 2 3 4 5
|
The '1' is just a random representation of id value.(values taken from a .text file)
Last edited on Aug 1, 2018 at 2:31pm
Jul 24, 2018 at 12:13pm
Might be easier to use an array of string like so.
1 2 3 4 5 6 7 8 9 10
|
string grid[] =
{
"######",
"# 1 #",
"# #",
"# 1 #",
"# #",
"# #",
"######"
};
|
other wise
1 2 3 4 5
|
char [6][6] =
{
{'#','#','#','#','#','#'},
// and so on
};
|
Another option (probably the best) would be a vector of string so you don't need to know beforehand how many rows and cols the grid has.
Last edited on Jul 24, 2018 at 12:15pm