• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What's an alternative to using switch in C++?

watdahel

Golden Member
What's an alternative to using a switch structure to represent my data file? Basically, I have a function that receives a string and checks too see if it's in the table and then returns another string that corresponds to it. I was gonna use a switch structure to do the look-up but I found out that the case values can't use string values.
 
char *Lookup(char *sz)
{
for (int i = 0; i < TABLE_SIZE; i++)
if (strcmp(keys, sz) != 0)
return values;
}

will this do?
You can also use a STL classes like map.
 
Back
Top