Enumeration versus array

前端 未结 5 1905
滥情空心
滥情空心 2021-01-16 05:57

I was wondering what would be better: An enumeration declaration or a string array:

enum MonthName{January, February, March, April, May, June, ...)
         


        
5条回答
  •  难免孤独
    2021-01-16 06:26

    There is nothing in common between enum and array. With the enum you cannot print the name of the month, this is just an integer...

    In your case you should use

    static const char* MonthName[2] = {"January", "February", ...};
    

提交回复
热议问题