c++ - How to convert an enum type variable to a string? -


how make printf show values of variables of enum type? instance:

typedef enum {linux, apple, windows} os_type;  os_type myos = linux; 

and need

printenum(os_type, "my os %s", myos); 

which must show string "linux", not integer.

i suppose, first have create value-indexed array of strings. don't know if beautiful way it. possible @ all?

there no beautiful way of doing this. set array of strings indexed enum.

if lot of output, can define operator<< takes enum parameter , lookup you.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -