C++:枚举

/*
#include 
using namespace std;
int main()
{
	enum days{one, two, three}day;
    day = one;
    switch(day){
        case one:
            cout << "one" << endl;
            break;
        case two:
            cout << "two" << endl;
            break;
        default:
            cout << "three" << endl;
            break;
		}
    return 0;
}
*/
/*

在main函数之外定义枚举

#include 
using namespace std;
enum time 
{ 
    first,second,
    third,forth,fifth
};

int main()
{
    enum time a=fifth;
    if (a==fifth) 
    {
        cout << "Succeed!";
    }
    return 0;
}
*/
#include
using namespace std;

int  main()
{
	//枚举里的变量直接引用
	//初值从0开始,然后逐次加1
    enum rank
    {
        first,second,third
    };

    int nRank=1;
    switch (nRank)
    {
        case first:
            cout << "第一名\n";
            break;
        case second:
            cout << "第二名\n";
            break;
        case third:
            cout << "第三名\n";
            break;
        default:
            break;
    }
	cout<

你可能感兴趣的:(C++)