Wednesday, January 18, 2012

Enumeration(列舉)

這樣他會自動以0為起點,印出3
#include <iostream>

using namespace std;

enum Numbers{ZERO, ONE, TWO, THREE};

int main(){

 Numbers num;
 num = THREE;

 cout << num << endl;

 return 0;
}
這樣則從自訂的1為起點,所以印出4
#include <iostream>

using namespace std;

enum Numbers{ZERO=1, ONE, TWO, THREE};

int main(){

 Numbers num;
 num = THREE;

 cout << num << endl;

 return 0;
}