Enum Program 1

Description:

In this C++ example, we demonstrate how to use an enum to define a type that could be used to represent Boolean logical values.

Example

#include <iostream>

int main() {
    using namespace std;

    // We can define an enum to represent boolean values.
    // In this case, keFalse = 0 and keTrue = 1.
    enum EBool {keFalse, keTrue};
    // Create an instance of the type and assign it the value keTrue.
    EBool eMyBool = keTrue;

    cout << "Boolean enum value = " << eMyBool << endl;
    // Output the constant enum values.
    cout << "keFalse = " << keFalse << endl;
    cout << "keTrue = " << keTrue << endl;

    // Keep the console window open.
    cin.get();
    return 0;
}

Output:

Enum Program 1 Output