#define Name(value) #value
enum {
value_a, value_b, value_c
};
printf("%s",Name(value_a));
#操作符解释
In function-like macros, a # operator before an identifier in the replacement-list runs the identifier through parameter replacement and encloses the result in quotes, effectively creating a string literal. In addition, the preprocessor adds backslashes to escape the quotes surrounding embedded string literals, if any, and doubles the backslashes within the string as necessary. All leading and trailing whitespace is removed, and any sequence of whitespace in the middle of the text (but not inside embedded string literals) is collapsed to a single space. This operation is called "stringification". If the result of stringification is not a valid string literal, the behavior is undefined.
Char* 转枚举值暂时没找到简单的
本文介绍了如何在C++中使用#define操作符将枚举值转换为字符串,并探讨了宏中的#操作符的工作原理,包括字符串化、转义字符和空白处理。然而,从char*转换回枚举值的方法相对较复杂。
2413

被折叠的 条评论
为什么被折叠?



