ccpp的enum

 1 /* enum */
 2 
 3 // c 语言
 4 
 5 #include<stdio.h>
 6 
 7 enum color{red=11,yellow,green,white};
 8 
 9 void main()
10 {
11     enum color c1;
12     cl = red;//  不注重数据类型
13     printf("%d\n",red);// 11
14     printf("%d\n",yellow);// 12
15     printf("%d\n",green);// 13
16 }
17 
18 
19 // c++ 语言
20 
21 #include<iostream>
22 
23 enum color:char{red='A',yellow,green,white};
24 
25 int main()
26 {
27     color mycolor = red;
28     //mycolor = 'A'; // 确保在枚举的范围之内不出错
29     mycolor = color::white;// 新语法
30 
31     color mycolor1(red);
32     color mycolor2(color::red);
33 
34     printf("%d,%c\n",red,red);
35     printf("%d,%c\n",yello,yello);
36     return 0;
37 }

 

posted on 2015-05-28 09:29  Dragon-wuxl  阅读(145)  评论(0)    收藏  举报

导航