Originally Posted by
Jonathan Yaniv
do i have to cout << dayVals[mon] ?
Yes.
Originally Posted by
Jonathan Yaniv
what if i want to print all the days in a loop, can't it be printed by dayVals[i] for e.g. ?
Yup. You can just run a for-loop over your dayVals array and use the loop index to access individual array elements. Beware that this will not work if your enum definition contains "holes", i.e.
Code:
enum Foo
{
Bar,
Blah,
Meep = 34, // <-- hole! enum values are not contiguous
Woosh
};
In such a case, your best bet may be writing a function to print enum values:
Code:
void printFoo( Foo enumVal, std::ostream& out )
{
switch ( enumVal )
{
case Bar:
out << "Bar";
break;
case Blah:
out << "Blah";
break;
case Meep:
out << "Meep";
break;
case Woosh:
out << "Woosh";
break;
default:
out << "UNRECOGNIZED Foo enum with integer value " << enumVal << "!";
}
}