注册 登录
编程论坛 C++教室

定义 C++/CLI枚举

hmsabc 发布于 2010-08-19 22:02, 1026 次点击
程序代码:
//定义 C++/CLI枚举

#include "stdafx.h"
//#include <iostream>

using namespace System;

enum class Suit{Clubs,Diamonds,Hearts,Spades};                  //全局范围定义牧举

int main(array<System::String ^> ^args)
{
    Suit suit = Suit::Clubs;                                     //定义 suit 为枚举类变量并使之等于 Clubs
    int value = safe_cast<int>(suit);                            //将 suit 强制类型转换为 int 并赋给 int 类变量 value
    Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value);
    suit = Suit::Diamonds;
    value = safe_cast<int> (suit);
    Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value);
    suit = Suit::Hearts;
    value = safe_cast<int> (suit);
    Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value);
    suit = Suit::Spades;
    value = safe_cast<int> (suit);
    Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value);
    //getchar( );
   
//system("pause");
    return 0;
}
0 回复
1