Skip to main content
GameDev.net gamedev.net
🔒 Locked

2d vector/array

Started by Ark86 Jan 22, 2005 at 11:07 PM 1 replies 850+ views
Original Post
Ark86
Ark86
To implement my menu system, I need to store strings in a 2 dimensional array/vector. I need to be able to add stuff on the fly so it is hard to implement it using standard arrays. I had tried something like this: vector< vector > but that didn't work when I tried to access things. Should that work? If so how will I access stuff? Thanks.
Deception666
Deception666
The problem might be that you are not allocating space for the string when inserting it into the vector. That might be the reason you are getting general exception when trying to access the array. A simple solution to the problem would be to use std::string.

vector< vector< std::string > >;

This will allow you to enter std::strings into your 2D vector. I personally wouldn't take this approach, but it is simple and you do not have to worry about allocating space for the string.
Zahlman
Zahlman
The other problem might be that when you have a vector >, you need to put vector's into it so that they can in turn hold the x's.

Although I can't tell you too much unless you are more specific about how it "didn't work".

Anyway, you might be interested in boost::multi_array. That container enforces rectangularity; a vector of vectors is explicitly not rectangular.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.