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.
Function i'm using
void CreateList()
{
std::string store;
std::string item;
std::cout << "What is the grocery store name" << std::endl;
std::cin >> store;
std::vector<std::string> store_list;
do {
std::cout << "Enter a list of items for this grocery store one at a time. When you are done, type done." << std::endl;
std::cin >> item;
if (item == "done") break;
store_list.emplace_back(item);
std::cout << "Added " << item << "to " << store << "list" << std::endl;
} while (true);
main() {
while (true)
{
int choice;
DisplayMenu();
cout<<"What menu choice would you like?"<<endl;
cin>>choice;
if (choice == 1)
CreateList();
if (choice == 2)
ExportLists();
if (choice == 3)
cout<<"Thank you for using!"<<endl;
break;
else
cout<<"Please enter a valid choice."<<endl;
}
map<string, vector<string> > list;
map<string, vector<string> >::iterator ListItr;
vector<string>::iterator VecItr;
for (ListItr = list.begin(); ListItr != list.end(); ++ListItr)
{
for (VecItr = ListItr ->second.begin();
VecItr != ListItr ->second.end();
++VecItr)
{
list[store].push_back(*VecItr);
}
}
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.