C++ string to enum

前端 未结 12 1280
无人及你
无人及你 2020-11-29 12:01

Is there a simple way in C++ to convert a string to an enum (similar to Enum.Parse in C#)? A switch statement would be very long, so I was wondering i

12条回答
  •  一整个雨季
    2020-11-29 12:45

    this worked for me:

    enum NODES { Cone = 1, BaseColor = 2, NONE = 0 };
    
    std::map nodeMap;
    nodeMap["Cone"] = NODES::Cone;
    nodeMap["BaseColor"] = NODES::BaseColor;
    

提交回复
热议问题