| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 770 人关注过本帖
标题:紧急求助
取消只看楼主 加入收藏
surivering
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-3-5
收藏
 问题点数:0 回复次数:1 
紧急求助

#include<iostream>
#include<list>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

template <class T>
void display(const T&c,char *label)
{
typename T::const_iterator iter=c.begin();
cout<<label;
for(;iter!=c.end();++iter)
cout<<*iter<<" ";
cout<<endl;
}
int main()
{
vector<int>v1,v2(3),v3(2,8);
display(v1,"v1=");
display(v2,"v2=");
display(v3,"v3=");
list<int> l;
l.push_back(9);
l.push_back(3);
l.push_front(5);
list<int>::iterator itr=l.begin();
l.insert(itr,1);
cout<<"itr points to"<<*itr<<endl;
l.insert(itr,7);
l.insert(itr,3);
set<int> s(l.begin(),l.end());//这里什么东西错了
s.insert(8);
display(1,"1= ");
display(s,"s= ");
cout<<count(1.begin(),l.end(),3)<<"3's exist in l\n";
itr=l.begin();
itr=find(itr,l.end(),7);
if(itr!=l.end())
cout<<"Found"<<*itr<<endl;
else
cout<<"Not found\n";
++itr;
itr=find(itr,l.end(),7);
if(itr!=l.end())
cout<<"Found"<<*itr<<endl;
else
cout<<"Not found\n";
if(binary_search(s.begin(),s.end(),7)==true)
cout<<"7 Found in set with B'Search.\n";
else
cout<<"7 Not found in set with B'Search.\n";
if(binary_search(s.begin(),s.end(),4)==true)
cout<<"4 Not found in set with B'Search.\n";
else
cout<<"4 Not found in set with B'Search.\n";
if(binary_search(s.begin(),l.end(),7)==true)
cout<<"7 Found in list with B'Search.\n";
else
cout<<"7 Not found in list with B'Search.\n";
}
这个帖子编译不能通过,说是定义set时出错,不知道是什么原因
C:\Program Files\Microsoft Visual Studio\MyProjects\s13\s13.cpp(30) : error C2664: '__thiscall std::set<int,struct std::less<int>,class std::allocator<int> >::std::set<int,struct std::less<int>,class std::allocator<int> >(const struct std::less<int>
&,const class std::allocator<int> &)' : cannot convert parameter 1 from 'class std::list<int,class std::allocator<int> >::iterator' to 'const struct std::less<int> &'
Reason: cannot convert from 'class std::list<int,class std::allocator<int> >::iterator' to 'const struct std::less<int>'
No constructor could take the source type, or constructor overload resolution was ambiguous

[此贴子已经被作者于2006-3-23 8:55:53编辑过]

搜索更多相关主题的帖子: display include 
2006-03-21 21:21
surivering
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-3-5
收藏
得分:0 

好了,改过了,还是不能通过,下面的那个英文看不懂啊

2006-03-22 11:22
快速回复:紧急求助
数据加载中...
 
   



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

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