2D Vectors

I need to make a 2-dimensional character vector so I can input data from a txt file into it however I cannot seem to find any clear way of doing this online. Also how would you make it to the right size (would you use .resize()). Cheers
Are you sure you want a 2D vector and not a vector of structures\classes that hold two variables?

AFAIK you can't make a 2D vector with the Standard lib. Think about it; it would be a continous block of memory that holds a variable number of elements who are them selves continous blocks of memory that are a variable size. Maybe some extended library has a way to fake this but I don't know of one.

Could you outline your issue in a little more detail?
I have been set to solve a maze which is in a text file which I will put below. So I was wanting to read the txt file using the istream and put the characters which make up the maze in to a 2-dimensional vector. I would use an array however my program should be able to solve any maze in a text file in the same format.
x = wall
p = path
g = goal
Always N x N maze and N is at the top of the text file i.e. 10 in this case


10
xxxxxxxxxx
xpxxpxxpgx
xppppxppxx
xxxppxpppx
xpppxxxxpx
xxxppppppx
xpppxxxxxx
xxxpxxxppx
xxxpppppxx
xxxxxxxxxx

cheers
How about a vector< string >?
That's really clever moorecm and doing that doesn't have any bounds issues (Honest Question)?
The problem is with that, when it comes to the process of solving the maze, it would make it much harder using a string surely?.........
Nope, a string can be treated as an array of chars with a variable length, this is because a string is an array of chars with a variable length. Each string entry would be a row and each element in the vector would be a new line. At this point it seems like a pretty good solution.
Topic archived. No new replies allowed.