Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ enum

#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
*/
 
PREVIOUS NEXT
Tagged: #enum
ADD COMMENT
Topic
Name
5+4 =