//============================================================================ // Name : Enum.cpp // Author : lf // Version :《C++语言基础教程》 吕凤翥 P33——P35 // Copyright : Your copyright notice // Description : 枚举enum基础知识 //============================================================================ #include <iostream> using namespace std; int main() { //枚举的定义 //enum中的数据实为整型int. //默认情况下这些枚举值从0开始,依次+1递增 enum day {Sun,Mon,Tue,Wed,Thu,Fri,Sat}; enum day sunDay; enum day monDay; enum day tueDay; sunDay=Sun; monDay=Mon; tueDay=Tue; cout<<"sunDay="<<sunDay<<endl; cout<<"monDay="<<monDay<<endl; cout<<"tueDay="<<tueDay<<endl; cout<<"--------------------"<<endl; //也可指定枚举开始的值. //其后的值依次+1递增 enum number {Number1=9527,Number2,Number3,Number4}; enum number num1=Number1; enum number num2=Number2; enum number num3=Number3; enum number num4=Number4; cout<<"num1="<<num1<<endl; cout<<"num2="<<num2<<endl; cout<<"num3="<<num3<<endl; cout<<"num4="<<num4<<endl; return 0; }
时间: 2024-09-23 16:04:05