## Recommended Posts

Rubiks14    143
how do you make a multidimentional array that has...lets say a column of strings and a column of integers? thanks, Rubiks14

##### Share on other sites
stylin    758
In what language?

##### Share on other sites
Rubiks14    143
sry bout that. C++

##### Share on other sites
SiCrane    11839
You can't. Arrays are homogeneous containers.

##### Share on other sites
Rubiks14    143
well that sucks...guess i'll have to use if statements

thanks anyway...saved me some stress :D

##### Share on other sites
stylin    758
Quote:
 Original post by Rubiks14how do you make a multidimentional array that has...lets say a column of strings and a column of integers?thanks, Rubiks14

Just how do you want to interact with this array? A std::map<...> might be what you're looking for, but I'd need more details to help more.

##### Share on other sites
Simian Man    1022
You could use an array of void*

##### Share on other sites
Rubiks14    143
ok i'm wanting to set up a multidimensional array that has in column 1 what the item is and in column 2 what the price of that item is (i'm just making kind of like a market for rpg just for some practice)

P.S. i'm also just wanting to use something that is in the area of what all i know. i just got through reading chap 3 in Beginning C++ Game Programming so basically the extint of my knowledge is multidimensional arrays

##### Share on other sites
Bezben    202
Sounds like what you want is:

struct rpg_item{    std::string item;    int         cost;};std::vector< rpg_item > item_list;

##### Share on other sites
Rubiks14    143
ummm...yea...i dunno what half of that means...i'm not that far in my book

##### Share on other sites
Zahlman    1682
It's quite simple, really. You make a thing that represents the pairing of a name and number, giving that the name "rpg_item" (or some other name that makes better sense to you; we can't see the rest of your project, after all). Now you can just make a simple 1-dimensional array of those. That makes things much neater, by strengthening the association between any given item name and its cost value.

Then, since arrays are evil, we make use of the standard library container std::vector.

If you "aren't that far in your book" yet, there's a good chance that your book is all out of order, and/or missing important topics (or covering useless or even potentially harmful ones). Which exactly are you using?

##### Share on other sites
Conner McCloud    1135
Quote:
 Original post by Simian ManYou could use an array of void*

You could use an array of bitfields. But why would you?

CM

## Create an account

Register a new account