Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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
	//...
}
 
PREVIOUS NEXT
Tagged: #enum
ADD COMMENT
Topic
Name
7+9 =