How do I ouput strings based on input when branching with if

How do I output strings when branching with if ?

For example with numbers you can do this


int num = 1

cout <<" please type a number 1-2" << endl ;

cin >> num ;

if (num == 2} {cout <<" you have selected number 2 " << endl ;

if (num == 1) {cout << "you have selected number 1" << endl ;}

Well I want to be able allow the user to type "hat" and output a message
based on the input, if (string == hat) {cout << " A black hat " << endl ;
if (string == fire) {cout << " water " << endl ; and so on.

If anyone can help thanks a lot.

Last edited on
1
2
3
4
5
6
std::string user_input;
std::cin >> user_input;
if(user_input == "hat")
{
    std::cout << "A black hat" << std::endl;
}
Last edited on
Thanks very much LB,


I really appreciate the help and fast response.


It works 100% thanks again.


Regards Cbasic88
Topic archived. No new replies allowed.