0

so right now I have the following code:

map<string, vector<vector<string>>> my_map;

vector<string> vec1 = {"Adam", "Kevin", "Sam"};
vector<string> vec2 = {"Apple", "Banana", "Pear"};
vector<string> vec3 = {"Cat", "Dog", "Mouse"};

my_map["Adam"].push_back(vec1);
my_map["Apple"].push_back(vec2);
my_map["Cat"].push_back(vec3);

I have the initialized map, my_map, and I want to print out all of the contents of its vectors in order. I currently have the following code:

for (auto it = my_map.begin(); it < my_map.end(); it++) {
    cout << it.first << " " << it.second[2] << '\n';
}

These lines (specifically the cout) do not compile, and I don't know why. Sublime is telling me "no member named first/second". It should print Sam Pear Mouse

Does anyone know what I'm doing wrong and how to fix this? Thanks

user313
  • 681
  • 1
  • 8
  • 21
  • @juanchopanza How specifically do I print out the contents? That is what I am having an issue with. It keeps giving me compiler errors. The question which I have been re-directed to does not answer this. – user313 Mar 21 '16 at 07:42
  • Start with a simpler map, e.g. `std::map` and build it up from there. And read the compiler errors and think about what they might mean. – juanchopanza Mar 21 '16 at 07:43

0 Answers0