Skip to content

Instantly share code, notes, and snippets.

@webber2408
Created April 12, 2020 08:18
Show Gist options
  • Save webber2408/bdf486239cdc3522d3784918d840a178 to your computer and use it in GitHub Desktop.
Save webber2408/bdf486239cdc3522d3784918d840a178 to your computer and use it in GitHub Desktop.
C++ Enumerations
#include<iostream>
using namespace std;
enum Direction {North, South, East, West} dir;
enum Gender {Male, Female};
int main(){
//Example 1
dir = East;
cout<<"Currenct Direction: "<<dir<<endl;
//dir = NorthEast; //Error: identifier "NorthEast" is undefined
for(int i= North; i<= West; i++){
cout<<i<<" ";
}
cout<<endl;
//Example 2
Gender g = Male;
cout<<"Gender: "<<g<<endl;
switch (g)
{
case Male:
cout<<"Male it is!"<<endl;
break;
case Female:
cout<<"Female it is!"<<endl;
break;
}
return 0;
}
/*
Output:
Currenct Direction: 2
0 1 2 3
Gender: 0
Male it is!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment