Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ enum

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;
}
Comment

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
*/
Comment

c++ enum

enum Animal{
	dog, // Same as dog = 0
  	cat, // Same as cat = 1
  	parrot, // Same as parrot = 2
};

enum Car{
	Ford = 3,
  	Nissan = 4,
  	Honda = 21,
};

//In main
std::cout << dog << std::endl; // Prints 0
std::cout << Ford << std::endl; // Prints 3

Car myCar = Nissan;
std::cout << myCar << std::endl; // Prints 4

if(myCar == Ford){ // False
	//... 
}else if(myCar == Nissan){ // True
	//...
}
Comment

enum c++

enum Foo { a, b, c = 10, d, e = 1, f, g = f + c };
//a = 0, b = 1, c = 10, d = 11, e = 1, f = 2, g = 12
Comment

enum in c++

#include <iostream>
using namespace std;
enum week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
int main()
{
    week today;
    today = Wednesday;
    cout << "Day " << today+1;
    return 0;
}
Comment

enum in c++

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // Defining enum Gender
    enum Gender { Male, Female };
 
    // Creating Gender type variable
    Gender gender = Male;
 
    switch (gender)
    {
    case Male:
        cout << "Gender is Male";
        break;
    case Female:
        cout << "Gender is Female";
        break;
    default:
        cout << "Value can be Male or Female";
    }
    return 0;
}
Comment

c++ enum

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;
}
Comment

enum c++

enum Colors
{
        BLACK,
        GREEN,
        BLUE,
        RED
};
Comment

c++ enum

/* Defining the enum */
enum vals {val1, val2, val3};

/* Setting a variable to an enum's value */
vals some_val;
some_val = val3;
Comment

enum c++

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;
}
Comment

enum c++

enum names {blah1, Blah2 , blah3};
Comment

PREVIOUS NEXT
Code Example
Cpp :: unique element in array in c 
Cpp :: c++ threadpool 
Cpp :: binary to decimal 
Cpp :: How to see gateway on linux 
Cpp :: define a type in c++ 
Cpp :: cpp foreach 
Cpp :: C++ insert character 
Cpp :: c++ allocate dynamic with initial values 
Cpp :: auto in cpp 
Cpp :: how togreper 
Cpp :: cuda shared array 
Cpp :: rc.local not running centos 6 
Cpp :: Maximum Pairwise Modular Sum codechef solution in c++ 
Cpp :: stack implementation 
Cpp :: The five most significant revisions of the C++ standard are C++98 (1998), C++03 (2003) and C++11 (2011), C++14 (2014) and C++17 (2017) 
Cpp :: c++ round number to 2 decimal places 
Cpp :: c++ anti debugging 
Cpp :: c++ take n number from the user and store them in array and get the max, min number of them and also find the average/summation of these numbers 
Cpp :: setFontSize QT 
Cpp :: cout ascii art c++ 
Cpp :: cout alternative c++ 
Cpp :: sideways triangle c++ xy plane 
Cpp :: nothrow new in cpp 
Cpp :: bnchch 
Cpp :: C++ Converting Celsius to Kelvin 
Cpp :: int to string Using boost::lexical_cast 
Cpp :: C++ selectin file location using Win32 API 
Cpp :: SDL_BlitSurface 
Cpp :: xor linked list 
Cpp :: initialise a vector c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =