求助vector iterator not dereferencable
我看的是C++primer的课后答案,程序如下。运行时出现 vector iterator not dereferencable 请求帮忙解决!多谢!!!#include<iostream>
#include<vector>
using namespace std;
bool is_equal(vector<int> &v1,vector<int>&v2)
{ for(vector<int>::const_iterator i=v1.begin(),j=v2.begin() ;i!=v1.end(),j!=v2.end();i++,j++)
{ if(*i!=*j)
{return false;
break;
}
}
return true;
}
int main()
{ int str1[6]={1,2,3,4,4,5};
int str2[8]={1,2,3,4,4,5,6,5};
int str3[5]={1,2,3,1,4,};
vector<int> vstr1(str1,str1+6);
vector<int> vstr2(str2,str2+8);
vector<int> vstr3(str3,str3+4);
if(is_equal(vstr1,vstr2))
cout << "vstr1 and vstr2 have the same part!!!"<<endl;
else cout <<"vstr1 and vstr2 have nothing in common!!!"<<endl;
if(is_equal(vstr1,vstr3))
cout << "vstr1 and vstr3 have the same part!!!"<<endl;
else cout <<"vstr1 and vstr3 have nothing in common!!!"<<endl;
if(is_equal(vstr3,vstr2))
cout << "vstr2 and vstr3 have the same part!!!"<<endl;
else cout <<"vstr2 and vstr3 have nothing in common!!!"<<endl;
return 0;
}