map test

// mapTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <map>
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
    map<string,int> test;
    test.insert(map<std::string,int> ::value_type("a",1));
    test.insert(map<std::string,int> ::value_type("b",2));
    map<string,int>::iterator it=test.begin();
    for (;it!=test.end();it++)
    {
        cout<<it->first<<","<<it->second<<endl;
    }

    int j=test["b"];
    printf("%d
",j);
    return 0;
}
/*
a,1
b,2
2
Press any key to continue
*/
原文地址:https://www.cnblogs.com/sky20080101/p/6640793.html