我需要将枚举成员(其值,而不是标识符)转换为字符串.我尝试了以下,它适用于MACRO(TYPE_A),但不适用于枚举值(typeA).在我看来,这有点奇怪.
你知道怎么做吗?
#define _tostr(a) #a
#define tostr(a) _tostr(a)
typedef enum _SPECIAL_FOLDER_ID {
typeA = 3,
typeB = 4,
} SPECIAL_FOLDER_ID;
#define TYPE_A 3
int main() {
//this is working, but the information is a macro (TYPE_A)
printf("The string is " tostr(TYPE_A) ".\n");
//this is not working for typeA (defined in an enumeration)
printf("The string is " tostr(typeA) ".\n");
return 0;
}
输出是:
The string is 3. The string is typeA.
我需要以某种方式修改代码,以便输出的第二行是"字符串是3".
谢谢!
PS:我不想使用printf打印该值.我需要一个包含该值的静态字符串.我只使用printf来测试结果......