How to map user input with enum value?

后端 未结 1 897
温柔的废话
温柔的废话 2021-01-29 15:45

I have a basic enum declaration:

enum Title {Prof, Dr, Mr, Mdm, Mrs, Miss, NA};

I\'m trying to map the user input(0,1,2,3,4,5,AnyN

相关标签:
1条回答
  • 2021-01-29 16:50

    An enum does not really store a series of characters as you seem to think, it just provides new names for some values of the underlying type (in your case, int). (This is somewhat simplified of course, but good enough to explain the observed behavior.)

    Thus, printing an enum-element does not print its "name", but will result in the element being converted to the underlying type and then printed.

    0 讨论(0)
提交回复
热议问题