C ++中的枚举类型或枚举
在本教程中,我们将讨论一个程序来理解C++中的枚举类型或枚举。
枚举类型是用户定义的数据类型,用户可以在其中指定可分配给变量的有限数量的值。
示例
#include <bits/stdc++.h>
using namespace std;
int main(){
//定义枚举变量
enum Gender {
Male,
Female
};
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;
}输出结果
Gender is Male
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志