match char* to enum

R

randy1200

I've received the following:

typedef enum { 10Hz, 100Hz } myfreq_t;

So in my code, if I say:

myfreq_t f;
f = 10Hz; //f = 0, as expected

If I say:

myfreq_t f;
f = (myfreq_t)argv[1]; //compile error,
//invalid cast

Any ideas on how to match a char* to an enum value. I'm on Red Hat Linux,
if that matters.

Thanks,
Randy
 
W

wittempj

This code can not work, as an enum is made of identifiers - they start
with a character, not with a number. You can probably better create a
vector of strings and let f be a string??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top