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 names {blah1, Blah2 , blah3};
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ template 
Cpp :: c++ inheritance 
Cpp :: polymorphism in c++ 
Cpp :: string number to integer number C++ 
Cpp :: c++ shell 
Cpp :: string comparison c++ 
Cpp :: c++ vector 
Cpp :: stl in c++ 
Cpp :: c++ forbids comparison between pointer and integer 
Cpp :: qt make widget ignore mouse events 
Cpp :: print hola mundo 
Cpp :: convert ascii char value to hexadecimal c++ 
Cpp :: oncomponentendoverlap ue4 c++ 
Cpp :: c++ code executio canntot proceed because glew32.dll was not founud 
Cpp :: hierarchical inheritance in c++ employee 
Cpp :: programs using vectors in c++ 
Cpp :: three way comparison operator c++ 
Cpp :: c++ random int troll 
Cpp :: c/c++ windows api socket wrappers 
Cpp :: what is throw in c++ 
Cpp :: async multi thread 
Cpp :: or in c++ 
Cpp :: find factorial in c++ using class 
Cpp :: c++ switch case 
Cpp :: enum in c++ 
Cpp :: gcd in cpp 
Cpp :: substring function in c++ 
Cpp :: Numbers Histogram in c++ 
Cpp :: c++ the hash function with 31 const 
Cpp :: use ster when declaring variables cpp 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =