fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. enum Color {red, blue};
  5. enum Number {three=3, four};
  6. enum Shape {circle, square};
  7.  
  8. struct article
  9. {
  10. enum Color color;
  11. enum Number number;
  12. enum Shape shape;
  13. } article_1;
  14.  
  15. //assume I have the below for all three enums
  16. std::istream& operator>>( std::istream& is, Color& I )
  17. {
  18. std::string tmp;
  19. if ( is >> tmp ) {
  20. for (auto&c:tmp)
  21. c=tolower(c);
  22. if (tmp=="red") I = red;
  23. else if (tmp=="blue") I = blue;
  24. }
  25. return is ;
  26. }
  27. std::ostream& operator<<( std::ostream& os, Color& O )
  28. {
  29. std::string tmp;
  30. switch (O) {
  31. case red: tmp="red"; break;
  32. case blue: tmp="blue"; break;
  33. default: tmp="oops!!";
  34. }
  35. return os<<tmp ;
  36. }
  37.  
  38.  
  39. int main ()
  40. {
  41. cout<<"Enter the Color : ";
  42. cin>>article_1.color;
  43. cout << "Result: "<<article_1.color<<endl;
  44.  
  45. // -------------------------- Comparison
  46. if (article_1.color==red)
  47. cout<<"Bingo!"<<endl;
  48. if (article_1.color!=blue)
  49. cout<<"Bingo again!"<<endl;
  50. if (article_1.color!=Color::blue)
  51. cout<<"Yet another Bingo!"<<endl;
  52.  
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0s 4372KB
stdin
Standard input is empty
stdout
Enter the Color : Result: red
Bingo!
Bingo again!
Yet another Bingo!