locked
string value of an enum RRS feed

  • Question

  • [Dalai Thread]

    does C++11 have a means to get the string value of an enum if not perhaps code/class?

    • Edited by Dalai Wednesday, April 2, 2014 11:54 AM
    Thursday, March 27, 2014 2:15 PM

Answers

  • Hi Dalai,

    C++ 11 not support to convert enum to string.

    See this 

    You need to implement a look up table like mechanism.
    The easiest way - Way 

    Thanks,

    Bhash

    • Marked as answer by Dalai Friday, March 28, 2014 9:26 AM
    Friday, March 28, 2014 5:33 AM

All replies

  • >does C++11 have a means to get the string value of an enum if not perhaps code/class?

    An enum value is an integer, so there is no string name for it at
    run-time.

    You're free to implement your own mechanism to provide a string
    interpretation for the enum values - a simple array of strings indexed
    by the enumeration value for example.

    Dave

    Thursday, March 27, 2014 2:56 PM
  • Hi Dalai,

    C++ 11 not support to convert enum to string.

    See this 

    You need to implement a look up table like mechanism.
    The easiest way - Way 

    Thanks,

    Bhash

    • Marked as answer by Dalai Friday, March 28, 2014 9:26 AM
    Friday, March 28, 2014 5:33 AM
  • The sprintf function can put the value of the enum into a C string.

    The ostringstream << operator can put the value of the enum into a C++ string.

    Friday, March 28, 2014 7:08 AM