zoukankan      html  css  js  c++  java
  • C++ STL map容器的说明测试1

    // maptest.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"

    /************************************************************************
    *
    * Map的特点: 1、存储Key-value对
    * 2、支持快速查找,查找的复杂度基本是Log(N)
    * 3、快速插入,快速删除,快速修改记
    *
    /************************************************************************/
    #include <iostream>
    #include <string>
    #include <map>
    using namespace std;


    int main()
    {
    map<const char*,int> m;
    m["a"]=1;
    m["b"]=6;
    m["c"]=9;
    map<const char*,int>::iterator it;
    it=m.begin();
    const char* c =it->first;
    cout<<"first element is :"<<c<<endl;
    int i = m["c"];
    while(it!=m.end()){
    cout << it->first<<";"<<it->second<<endl;
    ++it;
    }
    cout <<"m["c"]="<<i<<endl;
    cout <<"sizeof m:"<<m.size()<<endl;
    cout <<"erase m["c"](1:succ 0:failed):"<<m.erase("c")<<endl;
    cout <<"erase m["c"]:"<<m.erase("c")<<endl;
    cout <<"sizeof m:"<<m.size()<<endl;
    cout<<"m[c]="<<m["c"]<<endl;
    cout<<"sizeof m :"<<m.size()<<endl;

    cout<<"-----------------"<<endl;
    it=m.begin();
    while(it!=m.end()){
    cout << it->first<<";"<<it->second<<endl;
    ++it;
    }
    return 0;

    }

    运行结果:

  • 相关阅读:
    几种排序(c#实现)
    仿 MVC 三大特性
    自定义顺序表ArrayList
    MSMQ消息队列
    IIS 负载均衡(ARR)
    AOP 编程
    SqlServer 存储过程
    mac下mysql5.7.10密码问题
    gearman参数说明
    增加响应header让ajax支持跨域
  • 原文地址:https://www.cnblogs.com/minggeqiuzhi/p/3919907.html
Copyright © 2011-2022 走看看