enum Color { red, green, blue };
Color r = red;
switch(r)
{
case red : std::cout << "red
"; break;
case green: std::cout << "green
"; break;
case blue : std::cout << "blue
"; break;
}
#include <iostream>
using namespace std;
// Creating an enum type
enum Weather {
Rainy, // Starts from 0
Cool, // This is 1
Thunderstorm, // This is 2
VeryBright // This is 3
// And continues...
};
/* Your Programs starts here */
int main()
{
// Creates a enum variable & assigning it into Rainy
Weather currentWeather = Rainy;
// Outputs 0 because its the first one
cout << currentWeather << endl;
// Changes the variable into VeryBright
currentWeather = VeryBright;
// Outputs 3 because its the last one
cout << currentWeather << endl;
return 0;
}
/* Output C:EnumsExample.exe :
0
3
end
*/
enum Color { red, green, blue };
Color r = red;
switch(r)
{
case red : std::cout << "red
"; break;
case green: std::cout << "green
"; break;
case blue : std::cout << "blue
"; break;
}