码迷,mamicode.com
首页 > 编程语言 > 详细

c++中的,枚举

时间:2015-05-28 17:50:36      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:

 

 

#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    //定义枚举类型,并指定其枚举元素的值
    enum color {  
         RED=3,
         YELLOW=6,
         BLUE=9
    };

    //声明枚举变量a和b,并为枚举变量a赋初值 
    enum color a=RED;
    color b;        //合法,与C语言不同

    // 输出枚举常量 
    cout<<"RED="<<RED<<endl;
    cout<<"YELLOW="<<YELLOW<<endl;
    cout<<"BLUE="<<BLUE<<endl;
    
    //枚举变量的赋值和输出
    b=a;
    a=BLUE;
    cout<<"a="<<a<<endl;
    cout<<"b="<<b<<endl;
    //a=100;   错误!
    //a=6      也错误!

    //枚举变量的关系运算
    b=BLUE;                            // 枚举变量的赋值运算
    cout<<"a<b="<<(a<b)<<endl;
    system("pause");
}

 

 

RED=3
YELLOW=6
BLUE=9
a=9
b=3
a<b=0
请按任意键继续. . .

c++中的,枚举

标签:

原文地址:http://www.cnblogs.com/zhuyaguang/p/4536423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!