mardi 7 juin 2016

How to use getline inside if statment?

if i want to input a getline with constant part and variable part..

for example:

constant part: "I_love"

variable part: "cat, dog, donkey, bird....."

I tried this code by writing: I_love cat

but i realized that "cat" will not be in string Variable, it will be with the constant part and Variable will not have any value

I want to tell the compiler "put cat in string Variable"

Please can any one tell me what is the problem??

       string UserInput, Variable;
       getline(cin,UserInput);
       if (UserInput == "constant_part" + Variable)
       {
       .....
       }

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire