标题:求助vector iterator not dereferencable
取消只看楼主
阿龙0403
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-10-17
 问题点数:0 回复次数:1 
求助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;
}
搜索更多相关主题的帖子: vector iterator not 
2008-10-17 21:50
阿龙0403
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-10-17
得分:0 
非常谢谢, 问题解决了!!!
2008-10-18 21:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-238913-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024907 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved