I'm writing a code to check if a person have visited a particular place before or not if true do nothing else add the new place to the list of visited place I'm using map to store the student name as a key and array the store places as follow
#include<map>
using namespace std;
map<string,string[]> stu_plac;
map<string,string[])::iterator it;
I could not find the roght way to search across 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 please help me to find the correct way to do this. Do I need to use multimap or other data structer to do this??
Data structure like map<string, vector<string> >
will work.
You can use for (size_t i = 0; i < it->second.size(); i++)
to traverse the vector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With