-
enum Help
I have a enum with a bunch of different things. Is there a way to check to see if something is equal the enum.
EX:
Code:
#include <iostream>
using namespace std;
enum myColor{RED, BLUE, GREEN};
int main()
{
string color;
myColor test;
cout << "Enter a Color: ";
cin >> color;
if (color == test)
{
cout << "The color you entered exist in my enum!\n";
}
else
{
cout << "Does not exist :( \n";
}
return 0;
}
If i am doing this wrong or there is a better way, please let me know thanks.
-
enums are basically ints with fancy names. The problem with your code is that you never assign a value to test so it's value is undefined. If you wanted to test if the user inputed one of those colors then you'll have to do some string comparisons. Sorry what you have won't work.