• 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版)

  • 相关阅读:
    Hibernate配置文件详解
    Struts工作原理、流程
    java三大框架原理
    JAVA三大框架的各自作用
    tomcat的种种
    jdk及tomcat的配置
    java-io-file
    JAVA-IO-文件过滤
    SPSS-单因素方差分析(ANOVA) 案例解析(转)
    SPSS-比较均值-独立样本T检验 案例解析(转)
  • 原文地址:https://www.cnblogs.com/herd/p/12069769.html
Copyright © 2020-2023  润新知