ccplusplus.com
Learn C, C++ Concepts
Friday, February 10, 2012
enum example in c++
/************************************************************************* * File : enumeration.cpp * Author : Saurabh Gupta * Desc : enum example in c++ * Source : http://www.ccplusplus.com/p/c_15.html * Created : 11:32 AM Friday, February 10, 2012 *************************************************************************/ #include
using namespace std; /* * By default, the first enumerator is assigned the integer value 0, * and each subsequent enumerator has a value one greater than the * previous enumerator */ enum WeekDay { Monday, // assigned 0 Tuesday, // assigned 1 Wednesday, // assigned 2 Thursday, // assigned 3 Friday, // assigned 4 Saturday, // assigned 5 Sunday // assigned 6 }; int main () { WeekDay day = Monday; for (int day = Monday; day < Sunday; day++) { cout << day << endl; } return 0; } /* * OUTPUT * [sgupta@rhel6x86 enum]$ c++ enumeration.cpp -o enumeration [sgupta@rhel6x86 enum]$ ./enumeration 0 1 2 3 4 5 [sgupta@rhel6x86 enum]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment