map test

#include <map>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

enum DiagnosticVariableType
{
    BOOLType = 100,
    UDINTType,
    USINTType,
    UINTType,
    REALType,
    LREALType,
    STRINGType
};


int main(int argc,  const char* argv[])
{
    printf("argv[1]:%s, length %d\n",argv[1],strlen(argv[1]));
    DiagnosticVariableType type;

    const char* p = argv[1];
    const char* str = "BOOL";
    printf("str:%s, length %d\n",str,strlen(str));

    //map< const char*, DiagnosticVariableType> TypeMap;
   map< string, int> TypeMap;
/*
    TypeMap["BOOL"] = BOOLType;
    TypeMap["UDINT"] = UDINTType;
    TypeMap["USINT"] = USINTType;
    TypeMap["UINT"] = UINTType;
    TypeMap["REAL"] = REALType;
    TypeMap["LREAL"] = LREALType;
    TypeMap["STRING"] = STRINGType;
*/
    TypeMap["BOOL"] = 100;
    TypeMap["UDINT"] = 101;
    TypeMap["USINT"] = 102;
    TypeMap["UINT"] = 103;
    TypeMap["REAL"] = 104;
    TypeMap["LREAL"] = 105;
    TypeMap["STRING"] = 106;
    if(strcmp(p, str) == 0)
    {
        printf("same.\n");
    }
    else
    {
        printf("different.\n");
    }
    printf("str:%s,value %d\n", str, TypeMap[str]);    
    printf("p:%s,value %d\n", p, TypeMap[p]);
    
    return 0;
}


你可能感兴趣的:(map test)