Thread: enum Help

  1. #1
    Registered User
    Join Date
    Sep 2004

    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.


    #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";
    cout << "Does not exist :( \n";
    return 0;
    If i am doing this wrong or there is a better way, please let me know thanks.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  2. enum switchcase and windows message q
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 01:16 PM
  3. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 03:51 AM
  4. Switch case and enum help
    By SomeCrazyGuy in forum C++ Programming
    Replies: 9
    Last Post: 04-21-2005, 08:53 PM
  5. enum
    By JerryL in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2004, 05:45 PM