鱼C论坛

 找回密码
 立即注册
查看: 1775|回复: 3

C++ STL 问题

[复制链接]
发表于 2016-7-30 09:36:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<iostream>
#include<set>
using namespace std;
int main()
{
        set<int> a;
        multiset<int> ma;
       
        a.insert(60);
        a.insert(-1);
        a.insert(3000);
        a.insert(60);

        cout<<a.count(3000)<<endl;
       
        cout<<"显示set中的元素内容"<<endl;
        PrintContents(a);
       
        //下面的语句为何编译报错?
        //ma.insert(a.begin(),a.end());
        ma.insert(3000);
        ma.insert(ma.end(),3);
       
        ......       
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-7-30 11:03:37 | 显示全部楼层
改成以下这样就没问题了:

#include<iostream>
#include<set>
using namespace std;
int main(void)
{
        set<int> a;
        multiset<int> ma;
       
        a.insert(60);
        a.insert(-1);
        a.insert(3000);
        a.insert(60);
        cout << a.count(3000) << endl;
        cout << "显示set中的元素内容" << endl;
        set<int >::iterator it = a.begin();
        while (it != a.end())
        {
                cout << (*it) << endl;
                ++it;
        }
        it = a.begin();
        while (it != a.end())
        {
                ma.insert((*it));
                ++it;
        }
        ma.insert(3000);
        multiset<int>::iterator i = ma.begin();
        cout << "以下是multiset" << endl;
        while (i != ma.end())
        {
                cout << (*i) << endl;
                ++i;
        }
        getchar();
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-30 12:39:45 From FishC Mobile | 显示全部楼层
谢谢您的回答。但是出问题是ma.insert(a.begin(),a.end());这一句。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-30 12:42:45 From FishC Mobile | 显示全部楼层
编译时无论如何都通不过,英文错误是构造函数不接受这样的参数
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-3 23:07

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表