码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-17 18:48:05      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

代码如下:

/*
        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

 

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

标签:

原文地址:http://www.cnblogs.com/davidgu/p/4737199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!