C ++ - multidimensional arrays

When working with multidimensional arrays, is it possible to assign two different types of variables to an array ...

For example, if you have an array int example[i][j], is it possible for iand to jbe two completely different types of variables, such as int and string?

+3
source share
6 answers

It looks like you are looking for:

std::vector<std::map<std::string, int> > myData1;

or perhaps:

std::map<int, std::map<std::string, int> > myData2;

First you need to resize the vector to the appropriate size before using the indexing operators:

myData1.resize(100);
myData1[25]["hello"] = 7;

... and the second will allow you to assign any element directly (and rarely):

myData2[25]["hello"] = 7;
+7
source

No. It's impossible. You might want to learn the STL scheme .

+3

, ++ integer (ex: int, long, unsigned int, size_t, char).

, std::map<std::string,mytype>, , .

+2
+2

, .

+1

, . std::map.

0

Source: https://habr.com/ru/post/1769426/


All Articles