Reputation:
I have to make a table with a two dimensional array in c++. The array will need to hold two strings and two integers. Is it possible to have strings and integers in the same array? And how?
Please help ! I`m new to programming
Upvotes: 0
Views: 9300
Reputation: 490148
This sounds like you probably want an array (or vector) of structures, where each structure contains a string and an int:
struct person {
int age;
std::string name;
};
std::vector<person> people(2);
In this case, you refer to the "rows" by number, and the "columns" by name, so the first string would be: people[0].name
and the second integer would be people[1].age
.
Upvotes: 4