C++ examples for Statement:switch
A switch statement on enum value
#include <iostream> using namespace std; int main(int argc, const char * argv[]) { enum class Colors { //from ww w . ja v a 2 s. co 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; }