#include <iostream>
#include <cstdint>
using namespace std;
// 1. Declare the scoped enum class with uint8_t as the underlying type
enum class ErrorCode : uint8_t {
None = 0,
Timeout = 1,
Overflow = 2,
Invalid = 3
};
// 2. Implement the toString function
// This function takes an ErrorCode and returns a human-readable string.
const char* toString(ErrorCode e) {
switch (e) {
case ErrorCode::None: return "None";
case ErrorCode::Timeout: return "Timeout";
case ErrorCode::Overflow: return "Overflow";
case ErrorCode::Invalid: return "Invalid";
default: return "Unknown"; // Safety fallback
}
}
int main() {
int x;
if (!(cin >> x)) return 0;
// 3. Convert the integer to our ErrorCode enum
// static_cast is used here because we trust the input range (0-3)
ErrorCode e = static_cast<ErrorCode>(x);
// 4. Output the string representation
cout << toString(e) << endl;
return 0;
}
Input
0
Expected Output
None