#include <iostream>
#include <cstdint>
using namespace std;
// Declare a scoped enum class ErrorCode : uint8_t
// with the following explicit values:
// None = 0
// Timeout = 1
// Overflow = 2
// Invalid = 3
enum ErrorCode{
None = 0, Timeout = 1, Overflow = 2, Invalid = 3
};
// Implement:
// const char* toString(ErrorCode e);
const char * toString(ErrorCode e){
switch(e){
case None: return "None";
case Timeout: return "Timeout";
case Overflow: return "Overflow";
case Invalid: return "Invalid";
default: " ";
}
}
int main() {
int x;
cin >> x;
// Input value is guaranteed to be in the range 0–3
ErrorCode e = static_cast<ErrorCode>(x);
cout << toString(e);
return 0;
}
Expected Output
None