• C++ map简单运用


     1 #include <iostream>
     2 #include <string>
     3 #include <map>
     4 
     5 using namespace std;
     6 
     7 typedef pair<float, string> TIntStrPair;
     8 
     9 map <int, TIntStrPair> IIStrMap; //<int, <float,string>>
    10 
    11 map <string, string> StrStrMap; // <string,string>
    12 
    13 int main(int argc, char *argv[]) {
    14 
    15     map <int ,string> IntStrMap;
    16     
    17     IntStrMap.insert(pair<int,string>(1, "Tom"));
    18     IntStrMap.insert(pair<int,string>(2, "Jimes"));
    19     IntStrMap.insert(pair<int, string>(3, "Mary"));
    20     IntStrMap.insert(make_pair(4, "Adom")); //use make_pair();
    21 
    22     map<int,string>::iterator it;
    23 
    24     for (it = IntStrMap.begin(); it != IntStrMap.end(); it++) {
    25         cout << it->first << " " << it->second << endl;
    26     }
    27 
    28 
    29     cout << "-------------------------------" << endl;
    30 
    31     IIStrMap.insert(pair<int, TIntStrPair>(1, pair<float, string>(1.1, "Tom")));
    32     IIStrMap.insert(pair<int, TIntStrPair>(2, pair<float, string>(2.1, "Fantex")));
    33 
    34         IIStrMap.insert(make_pair(3, make_pair(3.2, "Jimes")));//use make_pair()
    35 
    36     map<int, TIntStrPair>::iterator It;
    37 
    38     for (It = IIStrMap.begin(); It != IIStrMap.end(); It++) {
    39         cout << It->first << " " << It->second.first << " " << It->second.second << endl;
    40     }
    41 
    42 
    43     cout << "----------------------------------" << endl;
    44 
    45     StrStrMap.insert(pair<string,string>("md5sum", "true"));
    46     StrStrMap.insert(pair<string,string>("sigcheck", "false"));
    47     StrStrMap.insert(pair<string, string>("ors_path", "/sdcard/ors"));
    48 
    49     StrStrMap.insert(make_pair("time_zone", "CTS"));// use make_pair();
    50 
    51     cout << "list the value " << endl;
    52 
    53     map<string, string>::iterator iter;
    54 
    55     for (iter = StrStrMap.begin(); iter != StrStrMap.end(); iter++) {
    56         cout << iter->first << " = " << iter->second << endl;
    57     }
    58 
    59     cout << "change the value " << endl;
    60 
    61     iter = StrStrMap.begin();
    62 
    63     iter = StrStrMap.find("md5sum");
    64     iter->second = "false";
    65 
    66     cout << "list the vale after change it " << endl;
    67 
    68     for (iter = StrStrMap.begin(); iter != StrStrMap.end(); iter++) {
    69         cout << iter->first << " = " << iter->second << endl;
    70     }
    71 
    72 
    73     cout << "----------------------------------------" << endl;
    74 
    75     cout << "erase the element " << endl;
    76 
    77     iter = StrStrMap.begin();
    78 
    79     iter = StrStrMap.find("md5sum");
    80     StrStrMap.erase(iter);
    81 
    82         for (iter = StrStrMap.begin(); iter != StrStrMap.end(); iter++) {
    83         cout << iter->first << " = " << iter->second << endl;
    84     }
    85 
    86 
    87     return 0;
    88 
    89 }
  • 相关阅读:
    jQuery 2.0.3 源码分析 Deferred(最细的实现剖析,带图)
    jQuery 2.0.3 源码分析 Deferrred概念
    jQuery 2.0.3 源码分析core
    jQuery 2.0.3 源码分析core
    JavaScript异步机制
    使用Node.js实现数据推送
    自定义jQuery插件Step by Step
    转 CSS hack:针对IE6,IE7,firefox显示不同效果
    ie6,ie7兼容性总结(转)
    QQ浏览器X5内核问题汇总
  • 原文地址:https://www.cnblogs.com/sn-dnv-aps/p/3486515.html
Copyright © 2020-2023  润新知