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

how to declare an enum variable c++

#include <iostream>
using namespace std;
enum direction {East, West, North, South};
int main(){
   direction dir;
   dir = South; 
   cout<<dir;   
   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++ inline if 
Cpp :: can derived class access private members 
Cpp :: frequency of characters in a string in c++ 
Cpp :: binary add using strings 
Cpp :: string array 2d c++ 
Cpp :: flags of open operation c++ 
Cpp :: opengl text rendering with 3d rendering 
Cpp :: qt graphics scene map cursor position 
C :: csrf_exempt 
C :: clear screen c 
C :: plt hide axis ticks 
C :: factorial c program using for loop 
C :: c random list 
C :: react-textfit 
C :: rl_replace_line 
C :: how to open jupyter notebook in local disk D 
C :: Calculator_C 
C :: input in c 
C :: how to ban websites on mac 
C :: reverse list in C 
C :: %d in c 
C :: c read csv 
C :: multiplication table in c using array 
C :: set value of boolean in c 
C :: sleep function in c 
C :: Bitwise Operators in C/C++ 
C :: bootstrap form 
C :: how to make a check bigger 
C :: convert string to int c 
C :: print an int c 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =