您好,欢迎来到微智科技网。
搜索
您的当前位置:首页STL - 常用关联容器代码 - set & multiset

STL - 常用关联容器代码 - set & multiset

来源:微智科技网

代码如下:

/*
        5. set & multiset
    */

    set<string> cities{
        "Braunschweig", "Hanover", "Frankfurt", "New York",
        "Chicago", "Toronto", "Paris", "Frankfurt"
    };
    multiset<string> dup_cities {
        "Braunschweig", "Hanover", "Frankfurt", "New York",
        "Chicago", "Toronto", "Paris", "Frankfurt"
    };
    cout << "cities before:" << endl;
    ContainerUtil<set<string>>::printElements(cities);
    ContainerUtil<multiset<string>>::printElements(dup_cities);

    cities.insert({ "London", "Munich", "Hanover", "Braunschweig" });
    dup_cities.insert({ "London", "Munich", "Hanover", "Braunschweig" });
    cout << "cities after:" << endl;
    ContainerUtil<set<string>>::printElements(cities);
    ContainerUtil<multiset<string>>::printElements(dup_cities);

运行结果:
cities before:
  Braunschweig  Chicago  Frankfurt  Hanover  New York  Paris  Toronto
  Braunschweig  Chicago  Frankfurt  Frankfurt  Hanover  New York  Paris  Toronto
cities after:
  Braunschweig  Chicago  Frankfurt  Hanover  London  Munich  New York  Paris  Toronto
  Braunschweig  Braunschweig  Chicago  Frankfurt  Frankfurt  Hanover  Hanover  London  Munich  New York  Paris  Toronto

 

转载于:https://www.cnblogs.com/davidgu/p/4737199.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务