   String to Enum ?
  Guys how canset a an enum type to the value in a string?Eg,enum eTEST{TYPEONE,TYPETWO};char string[] = "TYPEONE";This fails as its char and enum type..eTest = string;I cannot cast can i ? Please advise;pete. 
  You could set up an array of strings, like so:char* vStrings[] = { "TYPEONE", "TYPETWO"};and use the value of your enums to address one of the strings from that array, like soenum eTest{ TYPEONE = 0,  TYPETWO};int val; char* pString = vStrings[ val];So if val was TYPEONE, then this would effectively make pString point at the string "TYPEONE". This is not very flexible though, and it relies on you keeping your string vector in sync with your enums.;  You could use std::map. std::map<std::string, eTEST> lookup;lookup["TYPEONE"] = TYPEONE;lookup["TYPETWO"] = TYPETWO;eTEST eTest = lookup["TYPEONE"];You can also do a reverse-lookup by setting up another map.   Kami no Itte ga ore ni zettai naru! ;  Ok guys I have a bad cold so forgive me if im a little dense here Thanks alot for quick suggestions.RedAnt, I understand your idea, its sound in practise but im not sure it solves my problem?Example,If I read a txt file to retrieve the strings. Then i have a switch statement of enums of the same name as the strings in my txt file. I need to match the string value to the relevent enum type, to enter the switch and perform the required case.I am using an enum as i cannot have a switch(string).So to use Redants I idea would again need a look up function to match a sting and return an int. Similiar to tangents idea? If this is the easiest way i shall do it.As if C can be so gay!Thanks for help guys.pete.;this article on cuj gives a very usuable, printable, streamable, iterable enum ;  Yeah, you''re right. Sorry my bad, I thought you wanted to turn an enum to a string. Should have read the topic more closely. I reckon tangentz'' idea might be more like what you need, even though I don''t understand it entirely (not a big STL man here).  ;  Why don't you just use an if-statement like this: if (strcmp(string, "TYPEONE") == 0){...}else if (strcmp(string, "TYPETWO") == 0){...}... Currently studying Computer Game Development at the Academy of Interactive Entertainment www.aie.vic.edu.au   [edited by - hogwash on February 11, 2004 7:39:39 PM];  well, off the bat using a map means less typing, more ecapslation, greater extenablilty, clearer and less error proneGranted, if hes doing it in C he''s got no real choice, if he''s doing it in C++ then using the STL is the natural line imo (also dropping char arrays for std::string) 