我不知道map的索引是字符串时该怎么办

解决方案 »

  1.   

    // map.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"
    #pragma warning(disable:4786)
    #pragma warning(disable:4251)
    #pragma warning(disable:4273)#include <map>
    using namespace std;
    struct ltstr
    {
    bool operator()(const char* s1, const char* s2) const
    {
    return strcmp(s1, s2) < 0;
    }
    };int main(int argc, char* argv[])
    {

    map<const char*, int, ltstr> months;
    months["january"] = 31;
    months["february"] = 28;
    months["march"] = 31;
    months["april"] = 30;
    months["may"] = 31;
    months["june"] = 30;
    months["july"] = 31;
    months["august"] = 31;
    months["september"] = 30;
    months["october"] = 31;
    months["november"] = 30;
    months["december"] = 31;
    map<const char*, int, ltstr>::size_type st = months.size();
    int i=months["january"];
    i=months["february"];
    months.clear();
    return 0;
    }