枚举值作为c ++中的字符数组 [英] Enum values as char array in c++

查看:177
本文介绍了枚举值作为c ++中的字符数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c ++中有枚举

enum color {
    BLACK,GREEN,RED
};

在java中,我可以使用 color.BLACK.name )将给我的字符串值。

In java i can receive the string value using color.BLACK.name() will give me the String value..

Do c ++有相同的行为或如何将枚举转换为char * p>

Do c++ have the same behaviour or how can i convert an enum to char*.

推荐答案

这样做的原因是C ++倾向于让你支付你所需要的(这使得有可能写出更多的高性能代码,如果你设计它)。

The reason for this is that C++ tends to make you "Pay for what you need only" (which makes it possible to write much more performant code if you design it cardefully).

代码项目拥有一篇文章,而google会打开很多其他的。

Code project has an article on this, and google will turn up many others.

这篇关于枚举值作为c ++中的字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆