NOTE: my question is not duplicate of How to convert an enum type variable to a string? . In that solution we give computer one of enum values but I want ot give it an int value and get its related value like below.
I have an enum and I want to give it an int number and get its value like below:
int main() {
int choice;
string level;
enum difficulty
{
Easy = 1,
Normal,
Hard
};
cout << "choice: ";
cin >> choice;
now if I enter 2 for choice, I expect to get "Normal" as an string. Something like:
string level = difficulty(choice); //choice = 2
cout << level; //output = Normal
EDIT: I'm not allowed to use arrays.