cin for enum?

I just came across the enum thing in my tutorial, and if I typed the following code:
enum yes_no {yes, no}
would it be able to ask the user to enter either yes or no, and then let the program convert the input into a value of yes_no, that is yes or no?
Because then I could use commands like:
1
2
3
if (yes_no == yes){
cout << "Correct answer!"
}
Last edited on
1
2
3
4
5
6
7
8
9
10
std::string input;
yes_no answer;
std::cin >> input;
if (input == "yes") { 
    answer = yes;
} else if (input == "no") {
    answer = no;
} else {
    std::cout << "Unknown value" << std::endl;
}
Topic archived. No new replies allowed.