-
Array in a Map
I was just curious if there was a way to pass an array as a value into a map without using a pointer. I am trying to do something like:
Code:
map <string,array> nameMap;
Here the key would be a string and the value would be an array. I was curious if I could do this without using pointers. When I compile this I get an error
Error:
Code:
17 `array' was not declared in this scope
17 template argument 2 is invalid
17 template argument 4 is invalid
17 ISO C++ forbids declaration of `nameMap' with no type
Line 17 here being the line I posted above.
This is just for my curiosity, let me know if anyone has any solutions.
-
No, as a map is a replacement for an array. However, you can create the map and then use a for loop to iterate through and put the array's elements in the map.
-
You could use a std::vector:
Code:
std::map<std::string, std::vector<T> >
Where T is the type you want to store in the vector.