|
-
March 10th, 2004, 04:18 AM
#1
get enum declarator to string
Hi,
is it possible to get the declarator name of an enum, for example :
enum day {
monday,
tuesday
};
and
day today=monday;
CString dayname=howto?( today );
so that "dayname" is "monday"??
I don´t want to use extra arrays with the names for exisiting big enums that i use in my programs, but want the names to show for status info..
I think that there must be a way to do this, cause for example the VS variable viewer can show during debugging the "names" for variables of type enum..
thanks,
Siggi
PS: sorry for the broken english.. :-(
-
March 10th, 2004, 08:19 AM
#2
If this post is in the wrong discussion group, maybe one of the administrators could move it to the right one.
-
March 10th, 2004, 08:34 AM
#3
In C++, there is no way to automatically convert enums into string equivalents.
The Visual Studio IDE is able to do it because it has access to your source code, which your running program doesn't (as the source code will have been compiled).
This kind of thing is normally done with a lookup table, or resource dll.
By the way, you can do this in C#, as all types are objects derived from the base object, which has a ToString method.
-
March 10th, 2004, 09:43 AM
#4
You could declare a map:
map<day, CString> x;
// populate it
x[monday] = "monday";
x[tuesday] = "tuesday";
...
// access it
dayname = x[enumVariable];
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
Please remember to rate useful answers. It lets us know when a question has been answered.
-
March 10th, 2004, 12:43 PM
#5
Originally posted by sdude
If this post is in the wrong discussion group, maybe one of the administrators could move it to the right one.
No....it is fine...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|