Is there a simple way to convert C++ enum to string?

后端 未结 30 2800
我在风中等你
我在风中等你 2020-11-22 10:37

Suppose we have some named enums:

enum MyEnum {
      FOO,
      BAR = 0x50
};

What I googled for is a script (any language) that scans all

30条回答
  •  我在风中等你
    2020-11-22 11:00

    A problem with answer 0 is that the enum binary values do not necessarily start at 0 and are not necessarily contiguous.

    When I need this, I usually:

    • pull the enum definition into my source
    • edit it to get just the names
    • do a macro to change the name to the case clause in the question, though typically on one line: case foo: return "foo";
    • add the switch, default and other syntax to make it legal

提交回复
热议问题