How to print an enumerator as a string, not an int?

Given an enum, it is easy enough to emit the values of the enumerators or of variables of the enumeration: G:\tmp>type enumvals. C #include typedef enum colors { red, orange, yellow, green, blue, indigo, violet } colors; int main() { colors c = violet; /* Need enum colors in C */ printf("%d\n", yellow); printf("%d\n", c); return 0; } G:\tmp>como enumvals. C Comeau C/C++ 4.3.4.1 (Mar 30 2005 22:54:12) for MS_WINDOWS_x86 Copyright 1988-2005 Comeau Computing.

All rights reserved. MODE:strict errors C++ G:\tmp>aout 2 6 A question comes up surprisingly often though: How do I get the string values that these numbers represent? IOWs, as 2 is yellow, how can I get to see yellow output and not the unhelpful (in some case) 2?

Well, there is no direct language support in C and C++ for obtaining the name of an enumerator value. Instead, you need to do something such as: #include typedef enum colors { red, orange, yellow, green, blue, indigo, violet, maxcolors } colors; void ... more.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions