永发信息网

C++程序问题,如何使用set集合和iterator迭代器,编写程序后出错,这道题,求12!配对

答案:2  悬赏:40  手机版
解决时间 2021-02-07 04:51
  • 提问者网友:那叫心脏的地方装的都是你
  • 2021-02-06 12:53
#include
#include
#include
using namespace std;
void main()
{
int num=0,f12=479001600;//12!
multiset s;
for(int n;cin>>n;)
if(f12%n==0)
{
set::iterator it=s.find(f12/n);
if(it!=s.end())
{
num++;
s.erase(it);
}else s.insert(n);
}
cout<
}
提示错误:
C:\Documents and Settings\Administrator\桌面\章节例题\ch05实验\7.1.2.cpp(14) : error C2440: 'initializing' : cannot convert from 'class std::_Tree,class std::allocator >::_Kfn,struct std::l
ess,class std::allocator >::iterator' to 'class std::_Tree,class std::allocator >::_Kfn,struct std::less,class std::allocator >::iterator'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\Administrator\桌面\章节例题\ch05实验\7.1.2.cpp(15) : error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::_Tree,class std
::allocator >::_Kfn,struct std::less,class std::allocator >::iterator' (or there is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\章节例题\ch05实验\7.1.2.cpp(18) : error C2664: 'class std::_Tree,class std::allocator >::_Kfn,struct std::less,class std::allocator >:
:iterator __thiscall std::multiset,class std::allocator >::erase(class std::_Tree,class std::allocator >::_Kfn,struct std::less,class std::allocator
>::iterator)' : cannot convert parameter 1 from 'class std::_Tree,class std::allocator >::_Kfn,struct std::less,class std::allocator >::iterator' to 'class std::_Treetd::multiset,class std::allocator >::_Kfn,struct std::less,class std::allocator >::iterator'
No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.
最佳答案
  • 五星知识达人网友:痴妹与他
  • 2021-02-06 13:21
set::iterator it=s.find(f12/n);
find返回的是一个set的内容,不是一个迭代器。
set::iterator it=s.begin();
或者set::iterator it=s.end();
可以返回一个迭代器。
全部回答
  • 1楼网友:西岸风
  • 2021-02-06 14:41
你好! 你声明的s是multiset multiset s; 怎么能将s.find返回的迭代器赋值给一个set::iterator 呢? 仅代表个人观点,不喜勿喷,谢谢。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯