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 :: vector search by element 
Cpp :: how to scan array in c++ 
Cpp :: prime factorisation of a number in c++ 
Cpp :: initialize 2d vector 
Cpp :: when was c++ created 
Cpp :: splice string in c++ 
Cpp :: how to erase a certain value from a vector in C++ 
Cpp :: play audio c++ 
Cpp :: c++ read each char of string 
Cpp :: how to send email in c++ program 
Cpp :: c++ binary search 
Cpp :: c++ remove numbers from vector if larger than n 
Cpp :: stl sort in c++ 
Cpp :: c++ split string by several space 
Cpp :: c++ set comparator 
Cpp :: how to code string to int converter c++ 
Cpp :: how to use cout function in c++ 
Cpp :: c++ function default argument 
Cpp :: rand() c++ 
Cpp :: conditional operator in c++ 
Cpp :: unreal engine c++ 
Cpp :: Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer. 
Cpp :: a square plus b square plus c square 
Cpp :: power of a number 
Cpp :: c++ hash combine 
Cpp :: how to download c++ portable compiler 
Cpp :: how to initialize 2d array with values c++ 
Cpp :: stl c++ 
Cpp :: rotate an array of n elements to the right by k steps 
Cpp :: string number to integer number C++ 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =