字符串重新枚举值presentation [英] string representation of enum values
本文介绍了字符串重新枚举值presentation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
GCC 4.4.2 C89
gcc 4.4.2 c89
我有以下枚举:
enum drop_options_e
{
drop_ssm,
drop_snm,
drop_ssb
};
我只是想知道这是获得字符串再从枚举presentation价值的最佳途径。
I am just wondering that is the best way to get the string representation value from the enum.
所以基本上,而不是为drop_ssm返回值为0,我能得到'drop_ssm'代替。
So basically, instead of returning the value of 0 for drop_ssm, I could get the 'drop_ssm' instead.
非常感谢任何建议,
推荐答案
一个办法是这样做:
enum drop_options_e
{
drop_ssm = 0,
drop_snm ,
drop_ssb ,
LAST_ENTRY /* Should be last entry */
};
const char* drop_options_s[LAST_ENTRY] = {"drop_ssm", "drop_snm", "drop_ssb"};
当你想要一个字符串,再枚举的presentation可以 drop_options_s [枚举];
when you want a string representation of an enum you can drop_options_s[enum];
这篇关于字符串重新枚举值presentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文