我正在编写一个代码来检查一个人之前是否访问过某个地方,如果没有,那么除了将新地点添加到访问地点列表中我将使用地图将学生名称存储为密钥和数组存储地点如下
#include<map>
using namespace std;
map<string,string[]> stu_plac;
map<string,string[])::iterator it;
Run Code Online (Sandbox Code Playgroud)
我无法找到在地图上搜索的roght方式
我尝试了以下方法:
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));
}
Run Code Online (Sandbox Code Playgroud)
我认为问题在于字符串迭代器的数组,请你帮我找到正确的方法来做到这一点.我是否需要使用multimap或其他数据结构来执行此操作?