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
Post a Comment