2 batuwuhanpei batuwuhanpei 于 2014.03.04 17:25 提问

一个acm题中出现的迭代器相关错误求解

#include
#include
#include

using namespace std;

int main()
{
int n,a,b;
int count1 = 0,count2 = 0;
map p;
vector xm;
vector xy;
while(scanf("%d",&n) != EOF)
{
for(int i = 0;i < n;++i)
{
scanf("%d%d",&a,&b);
p[a] = b;
}
vector::iterator iter1;
xm.push_back(p[1]);
iter1 = xm.begin();
while(p.count(*iter1))
{
xm.push_back(p[*iter1]);
++iter1;
}
vector::iterator iter2;
xy.push_back(p[2]);
iter2 = xy.begin();
while(p.count(*iter2))
{
xy.push_back(p[*iter2]);
++iter2;
}
iter1 = xm.begin();
iter2 = xy.begin();
int flag = 0;
for(;iter1 != xm.end();++iter1,++count1)
{
if(flag)
break;
for(;iter2 != xy.end();++iter2,++count2)
{
if(*iter1 == *iter2)
{
if(count1 == count2)
{
printf("%s\n","You are my brother");
flag = 1;
}
else if(count1 > count2)
{
printf("%s\n","You are my elder");
flag = 1;
}
else
{
printf("%s\n","You are my younger");
flag = 1;
}
}
}
count2 = 0;
}
}

return 0;

}
大家好,我想问一下为什么在我执行代码执行到++iter1的时候,总是出现Debug Assertion Failed的错误,出现的是对话框,提示是:Expression:("this->_Has_container()",()),这事什么原因了?该如何解决呢?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!