| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4697 人关注过本帖
标题:求助vector iterator not dereferencable
只看楼主 加入收藏
阿龙0403
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-10-17
收藏
 问题点数:0 回复次数:5 
求助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
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
你用的什么编译平台?
这样做试试,
bool is_equal(vector<int> &v1,vector<int>&v2)
{
    vector<int>::const_iterator i=v1.begin();
    vector<int>::const_iterator j=v2.begin() ;
    for(;i!=v1.end(),j!=v2.end();++i,++j)
    {
        if(*i!=*j)
        {
            return false;
        }
    }
    return true;
}
2008-10-17 22:55
newyj
Rank: 2
等 级:新手上路
威 望:3
帖 子:542
专家分:0
注 册:2008-1-4
收藏
得分:0 
用dev-c++编译  能运行
bool is_equal(vector<int> &v1,vector<int>&v2)中的vector<int>&v2少空格吧?
2008-10-17 23:00
caoxiongwei12
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-10-17
收藏
得分:0 
vector<int> vstr1(str1,str1+6);看这里有没有错
2008-10-18 00:14
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
;i!=v1.end()&&j!=v2.end();

学习需要安静。。海盗要重新来过。。
2008-10-18 18:50
阿龙0403
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-10-17
收藏
得分:0 
非常谢谢, 问题解决了!!!
2008-10-18 21:08
快速回复:求助vector iterator not dereferencable
数据加载中...
 
   



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

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