I am writing code to check whether a person has visited a place before or not, if the truth does nothing, add a new place to the list of visited places. I use a map to store the studentβs name as a key and an array of storage, as shown below.
#include<map> using namespace std; map<string,string[]> stu_plac; map<string,string[])::iterator it;
I could not find a way to search on the map
I tried the following:
bool exist=false; if(stu_plac.count(name)) { it=stu_plac.find(name); for(auto tt=(*it).second.begin(); tt!=(*it).second.end(); tt++) { if (tt.compare(place)==0)//exist { exist=true; } break; } if (!exist) { (*it)second[++tt]=place; } } else { stu_plac.insert(pair<string,string[]>(name,place)); }
I think the problem is with the array of string iterator, can you help me find the right way to do this. Do I need to use a multi-mast or other data structure for this?
source share