鱼C论坛

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

给点挑战吧,请问哪位大侠敢进来解决我的C++问题呢?求助!!!!

[复制链接]
发表于 2012-11-1 23:14:07 | 显示全部楼层 |阅读模式

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

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

x
//setops.cpp -- some set operations
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <iterator>

int main()
{
        using namespace std;
        const int N = 6;
        string s1[N] = {"buffoon","thinkers","for","heavy","can","for"};
        string s2[N] = {"metal","any","food","elegant","deliver","for"};

        set<string> A (s1,s1+N);
        set<string> B (s2,s2+N);
        ostream_iterator<string,char> out (cout," ");
        cout<<"Set A: ";
        copy(A.begin(),A.end(),out);
        cout<<endl;
    cout<<"Set B: ";
        copy(B.begin (),B.end(),out);
        cout<<endl;
       
        cout<<"Union of A and B: \n";
        set_union(A.begin(),A.end(),B.begin(),B.end(), out);
        cout<<endl;

        cout<<"Intersection of A and B: \n";
        set_intersection(A.begin(),A.end(),B.begin().B.end(),out);
        cout<<endl;
       
    cout<<"Difference of A and B: \n";
        set_difference(A.begin(),A.end(),B.begin().B.end(),out);
        cout<<endl;

        set<string> C;
        cout<<"Set C: \n";
        set_union(A.begin(),A.end(),B.begin(),B.end(),insert_iterator<set <string> > (C,C.begin()));
        copy(C.begin(),C.end(),out);
        cout<<endl;

        string s3("grungy");
        C.insert (s3);
        cout<<"Set C after insertion: \n";
        copy(C.begin(),C.end(),out);
        cout<<endl;
       
        cout<<"Showing a range: \n";
        copy(C.lower_bound("ghost"),C.upper_bound("spook"),out);
        cout<<endl;
       
        return 0;
}


运行不了啊!!!!为什么呢:'(
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-11-3 08:54:54 | 显示全部楼层

//setops.cpp -- some set operations
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
       
        const int N = 6;
        string s1[N] = {"buffoon","thinkers","for","heavy","can","for"};
        string s2[N] = {"metal","any","food","elegant","deliver","for"};

        set<string> A (s1,s1+N);

        set<string> B (s2,s2+N);

        ostream_iterator<string,char> out (cout," ");

        cout<<"Set A: ";

        copy(A.begin(),A.end(),out);

        cout<<endl;

        cout<<"Set B: ";
        copy(B.begin (),B.end(),out);
        cout<<endl;

        cout<<"Union of A and B: \n";
        set_union(A.begin(),A.end(),B.begin(),B.end(), out);
        cout<<endl;

        cout<<"Intersection of A and B: \n";
        set_intersection(A.begin(),A.end(),B.begin(),B.end(),out);
        cout<<endl;

        cout<<"Difference of A and B: \n";
        set_difference(A.begin(),A.end(),B.begin(),B.end(),out);
        cout<<endl;

        set<string> C;
        cout<<"Set C: \n";
        set_union(A.begin(),A.end(),B.begin(),B.end(),insert_iterator<set <string> > (C,C.begin()));
        copy(C.begin(),C.end(),out);
        cout<<endl;

        string s3("grungy");
        C.insert (s3);
        cout<<"Set C after insertion: \n";
        copy(C.begin(),C.end(),out);
        cout<<endl;

        cout<<"Showing a range: \n";
        copy(C.lower_bound("ghost"),C.upper_bound("spook"),out);
        cout<<endl;

        return 0;
}

编译运行成功!,问题你是set_intersection( )传参问题,仔细检查。
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2012-11-3 13:09:24 From FishC Mobile | 显示全部楼层
游魂战车 发表于 2012-11-3 08:54
//setops.cpp -- some set operations
#include
#include

你用什么软件运行?我用vc6,就出现问题啊?它的那个参数可以吧?你把结果给我,谢谢
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-11-3 21:59:45 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-11-16 02:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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