title: C++:Storing Items in a vector into a map
body: <p>The main program must store the grocery lists in a map of key-value pairs called: lists. The key must be a string containing a grocery store name and the value must be a vector of strings containing the grocery list of items for that store.</p>
  
  <p>Function i'm using</p>
  
  <pre><code>void CreateList() 
  {  
  std::string store;
  std::string item;
  std::cout &lt;&lt; "What is the grocery store name" &lt;&lt; std::endl;
  std::cin &gt;&gt; store;
  
  std::vector&lt;std::string&gt; store_list;
  do {
      std::cout &lt;&lt; "Enter a list of items for this grocery store one at a time. When you are done, type done." &lt;&lt; std::endl;
      std::cin &gt;&gt; item;
      if (item == "done") break;
      store_list.emplace_back(item);
      std::cout &lt;&lt; "Added " &lt;&lt; item &lt;&lt; "to " &lt;&lt; store &lt;&lt; "list" &lt;&lt; std::endl;
  } while (true);
  </code></pre>
  
  <p>main()
  {</p>
  
  <pre><code>while (true)
  {
      int choice;
      DisplayMenu();
      cout&lt;&lt;"What menu choice would you like?"&lt;&lt;endl;
      cin&gt;&gt;choice;
      if (choice == 1)
          CreateList();
      if (choice == 2)
          ExportLists();
      if (choice == 3)
          cout&lt;&lt;"Thank you for using!"&lt;&lt;endl;
          break;
      else
      cout&lt;&lt;"Please enter a valid choice."&lt;&lt;endl;
  }
  map&lt;string, vector&lt;string&gt; &gt; list;
  map&lt;string, vector&lt;string&gt; &gt;::iterator ListItr;
  vector&lt;string&gt;::iterator VecItr;
  for (ListItr = list.begin(); ListItr != list.end(); ++ListItr)
  {
      for (VecItr = ListItr -&gt;second.begin();
          VecItr != ListItr -&gt;second.end();
          ++VecItr)
      {
          list[store].push_back(*VecItr);
      }
  
  }
  </code></pre>
  
  <p>My problem is I can't figure out how to properly iterate through the vector created in CreateList() and add items in that vector to the map, which I'm also having a hard time figuring out how to get the grocery store name for. Would I have to have the CreateList() function return something in order to do this? This is my first attempt at a C++ program transitioning from python so please simplify all answers. Thanks for your time.</p>