这个程序不深,只是告诉我们,map的键可以是enum类型。
#include <map>
#include <string>
#include <stdio.h>
using namespace std;
enum REG{
STATUS = 0x1000,
RELEASE_ID = 0x1010,
};
int main(int argc, const char *argv[])
{
map<
enum REG, int> word_count;
word_count[STATUS] = 20000;
word_count[RELEASE_ID] = 54232;
printf("a = %d\n",
word_count[STATUS]);
printf("b = %d\n", word_count[RELEASE_ID]);
return 0;
}
输出结果是:
a = 20000
b = 54232