C++ enum value on switch statement

Description

C++ enum value on switch statement

#include <iostream> 
  
using namespace std; 
  
int main(int argc, const char * argv[]) 
{ 
        enum class Colors 
        { /*from   ww w .  j a  v  a 2s.c  om*/
            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