C++ switch statement on enum value

Description

C++ switch statement on enum value

#include <iostream> 
  
using namespace std; 
  
int main(int argc, const char * argv[]) 
{ 
        enum class Colors 
        { /*from w w w.  j  a  v a 2 s  .  c o  m*/
            Red, 
            Green, 
            Blue 
        }; 
        Colors color = Colors::Red; 
        switch (color) 
        { 
            case Colors::Red: 
                { 
                    cout << "The color is Red!"; 
                } 
                break; 
              
            case Colors::Green: 
                { 
                    cout << "The color is Green"; 
                } 
                break; 

            default: 
                { 
                    cout << "Unknown color!"; 
                } 
                break; 
        } 
      
        return 0; 
}



PreviousNext

Related