C++ 枚举转字符串

用#宏,见代码

#include <iostream>

#define enum_to_string(x) #x

enum sex
{
    boy,
    girl,
};

int main()
{
    std::cout << enum_to_string(sex::boy) << std::endl;
    system("pause");
}

输出结果:

posted @ 2015-02-06 16:24  莫压枯枯地  阅读(6631)  评论(0编辑  收藏  举报