enum and overloading operator<<

This is a discussion on enum and overloading operator<< within the C++ Programming forums, part of the General Programming Boards category; Consider the enumeration type enum Colors {red, blue, green yellow, violet}; Implement the overloaded operator << that outputs the value ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    9

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    Like for example
    Code:
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    8
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21