0

Is there any way to directly get the name of an enumeration element instead of its value. For example:

enum months {Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};
int main(){
    months thisMonth = Mar;
    cout << "The next month is " << thisMonth+2;
}

The output will be The next month is 4 How to get the output The next month is Apr (directly without any extra code)??

  • 2
    You can't. Once the program is compiled, the names of the months are gone. You need to do this yourself by using a `std::map` for example. – Jabberwocky Mar 08 '23 at 12:31

0 Answers0