#include using namespace std;void main(){\x05enum day{sunday,monday,tuesday,wendsday,thursday,friday,stadurday};\x05day today; //就是这一行,\x05today=monday;\x05if (today==sunday||today==stadurday)\x05{\x05\x05cout
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/22 11:36:20
#include using namespace std;void main(){\x05enum day{sunday,monday,tuesday,wendsday,thursday,friday,stadurday};\x05day today; //就是这一行,\x05today=monday;\x05if (today==sunday||today==stadurday)\x05{\x05\x05cout
#include
using namespace std;
void main()
{
\x05enum day{sunday,monday,tuesday,wendsday,thursday,friday,stadurday};
\x05day today; //就是这一行,
\x05today=monday;
\x05if (today==sunday||today==stadurday)
\x05{
\x05\x05cout
#include using namespace std;void main(){\x05enum day{sunday,monday,tuesday,wendsday,thursday,friday,stadurday};\x05day today; //就是这一行,\x05today=monday;\x05if (today==sunday||today==stadurday)\x05{\x05\x05cout
enum day{sunday,monday,tuesday,wendsday,thursday,friday,stadurday};
这句定义了符号化的常量sunday,monday等等.在下面的程序中,可以声明枚举型变量day today,对其赋值,或者判断它的值.
定义枚举型的好处主要有二,首先增强程序可读性,sunday、monday肯定比0,1容易理解;其次可以对变量类型与取值进行限定.
枚举型常量即某种枚举型的合法取值,此例中,sunday,monday,tuesday,wendsday,thursday,friday,stadurday是枚举型常量.在编译时确定各个常量的对应值.枚举型变量指的是声明为已定义枚举类型的变量.如此例中的today.
用枚举型常量定义变量,这个说法不太明确,其实包含了三个阶段,一,定义一种枚举类型;二,声明某个变量为该枚举类型;三,用枚举型常量向该变量赋值