C++枚举类型

2018-01-02  本文已影响0人  teanee

enum week {

        monday,

        tuesday,

        wednesday,

        thursday,

        friday,

        saturday,

        sunday

    } day1;

    day1 = monday;

    enum week day2;

    day2 = tuesday;

    cout<<day1<<endl;

    cout<<day2<<endl;

在声明枚举类型时需要使用enum,在创建实例时不需要使用enum关键字。

enum test {

        a,

        b=5,

        c,

        d,

        e,

        f,

        g

    };

    enum test t1;

    t1 = a;

    enum test t2;

    t2 = d;

    cout<<t1<<endl;

    cout<<t2<<ebdl;

运行结果:

0

7

枚举内的值如果为赋值的话是依次增加的。

上一篇 下一篇

猜你喜欢

热点阅读