struck UP{}; //枚举 enum TYP{ T, Q };
struck UP{}; //枚举 enum TYP{ T, Q };
枚举中的值是按,01234进行排序
如果新增一个枚举会按最后枚举的值加一变成新枚举的值
enum 名字{
Tank,
Magic,
ADC,
Assist
};
名字 heroType=Tank;
枚举类型enum
枚举 是为了方便记录类型
栗子
enum type
{magic,tank,fighter};
…………………………
不赋值的话默认
magic=0
tank=1
fighter=2
各元素之间用英文逗号分隔
herotype=定义
return 0; 枚举类型
枚举类型取值
Tank
Magic
ADC
Assist
定义枚举类型
#include <iostream>
using namespace std;
//枚举
enum HeroType
{
Tank,
Magic,
ADC,
Assist
};
int main()
{
//int heroType = 1;
HeroType heroType = Tank;
heroType = ADC;
cout << heroType << endl; // 2
int i = ADC + 2;
cout << i << endl;// 4
heroType = HeroType(3);
cout << heroType << endl; // 3
return 0;
}
#include <iostream>
using namespace std;
//枚举
enum HeroType
{
Tank = 1,
Magic = 4,
ADC = 7,
Assist // 8
};
int main()
{
//int heroType = 1;
HeroType heroType = Tank;
heroType = ADC;
cout << heroType << endl; // 7
int i = ADC + 2;
cout << i << endl;// 9
heroType = HeroType(3);
cout << heroType << endl; // 3
return 0;
}
枚举类型关键字 enum herotype{
tank,0
adc,1
assidt 2
};
int main(){
heroType heroType=tank;
hero
}