Essentially, I have a structure of VideoGame statistics like the following in my C++ program:
struct Game
{
string title;
genre this_genre;
int this_rank;
float time;
};
I also have defined the enumerated type genre as this:
enum genre {FPS, MOBA, ROLEPLAY};
I have declared an abstract structure variable called NewGame
Game NewGame
My goal is the have the user define the members of the structure variable NewGame from standard input. I have no problem doing that for the other members of the structure, but I cannot seem to figure out how to get the user to store an enumerator in the enumerated member of the structure.
cout << "Enter the title for your game: ";
getline(cin, NewGame.title);
cout << "Enter the rank of your game: ";
cin >> NewGame.this_rank;
// The genre currently breaks the code:
cout << "Enter the genre of the game: ";
cin >> NewGame.this_genre;
cout << "Enter the time (days) spent playing your game: ";
cin >> NewGame.time;
I tried static casting it as an integer, but then I overloaded the insertion operator.
cin >> static_cast<int>(NewGame.this_genre); // doesn't work.
I want for the user to be able to provide values 0, 1, or 2, and have those respectively be assigned to FPS (0), MOBA (1), or ROLEPLAY (2).
What am I doing wrong? What am I not understanding?