形式如下:
enum 枚举类型名 {变量值列表}
例如:
enum weekday{sun,mon,tue,wed,thu,fri,sat};
#include<iostream.h>
enum game_result{WIN,LOSE,TIE,CANCEL};//定义枚举类型
int main()
{
game_result result; //定义枚举类型变量result
enum game_result omit=CANCEL; //定义枚举类型变量omit
int count;
for (count=WIN;count<=CANCEL;count++)
{
result=(game_result)count;
if (result==omit)
cout<<"The game was cancelled\n";
else
{
cout<<"The game was played ";
if (result==WIN)
cout<<"and we won!";
if(result==LOSE)
cout<<"and we lost.";
cout<<endl;
}
}
return 0;
}