zoukankan      html  css  js  c++  java
  • C++ Multimap运用实例

    C++ Multimap运用实例

    #include <map>
    #include <string>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
        multimap<string, string> dict1;
        dict1.insert({ { "day","Tag" }, { "strange","fremd" }, { "car","Auto" },
        { "smart","elegant" }, { "trait","Merkmal" }, {"strange","seltsam"},
        { "smart","raffiniert" }, { "smart","klug" }, {"clever","raffiniert"} });
    
        //print all element
        cout.setf(ios::left,ios::adjustfield);
        cout << "" << setw(10) << "english german " << endl;
        cout << setfill('-') << setw(20) << "  " << setfill(' ') << endl;
    
        for (const auto& elem1:dict1)
        {
            cout << "  " << setw(10) << " " << elem1.first << "  " << elem1.second << endl;
        }
        cout << endl;
    
    
        string word1("smart");
        cout << "word1:" << word1 << endl;
        for (auto pos1 = dict1.lower_bound(word1);pos1 != dict1.upper_bound(word1);++pos1)
        {
            cout << "" << pos1->first << "   " << pos1->second << endl;
        }
        cout << endl;
    
        string word2("raffiniert");
        cout << "word2:" << word2 << endl;
        for (const auto& elem1:dict1)
        {
            if (elem1.second == word2)
            {
                cout << elem1.first << "  " << elem1.second << endl;
            }
        }
    
        system("pause");
        return 0;
    }

    english german
    ------------------
    car Auto
    clever raffiniert
    day Tag
    smart elegant
    smart raffiniert
    smart klug
    strange fremd
    strange seltsam
    trait Merkmal

    word1:smart
    smart elegant
    smart raffiniert
    smart klug

    word2:raffiniert
    clever raffiniert
    smart raffiniert
    请按任意键继续. . .

    代码参考:C++标准库(第2版)

  • 相关阅读:
    实用函数,array_column。从二维数组中获取想要的一位数组。
    解决小程序swiper层级太高问题
    小程序模拟领红包
    小程序,红包弹出层布局
    小程序核销功能
    小程序 text标签中一定 不要换行,不要随便格式化!!!
    小程序动态修改json中的配置
    小程序支付
    docker常用命令
    ssh修改默认端口
  • 原文地址:https://www.cnblogs.com/herd/p/12069769.html
Copyright © 2011-2022 走看看