Thread: enum and overloading operator<<

  1. #1
    Registered User
    Join Date
    Feb 2004

    enum and overloading operator<<

    Consider the enumeration type

    enum Colors {red, blue, green yellow, violet};

    Implement the overloaded operator << that outputs the value of a Colors object as an enumeration value.

    ostream &operator<< (ostream &ostr, const Colors &obj);

    Can you help me with this part

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Like for example
    if ( obj == red ) cout << "red";
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2004
    I think I just asked this question in my thread, only a little more elaborately...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. custom enum class (operator overloading)
    By l2u in forum C++ Programming
    Replies: 16
    Last Post: 04-28-2008, 03:22 PM
  2. Overloading Enumerated Types?
    By Witch_King in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2001, 04:57 AM