hey guys ive been reading the pdf tutorial and i checked the "if and else" and i wanted to know if i can do this:
1 2 3 4 5 6 7 8
string mystring = "are you okay";
cout << mystring << " ";
if ("yes")
then
cout << "ohh then lets keep talking";
else
then
cout << "Whatever";
All i want to know if the person says "yes" can i answer something and if it says something else i can say something different than the first answer of yes AND terminate the program
On line 3 you are evaluating the truth value of the C-style string "yes", { 'y', 'e', 's', '\0' }, it's basically a pointer to the first character, and indeed a pointer pointing to an allocated memory (so not a NULL pointer).
Because it's not NULL, if ("yes") always evulates true.
You actually mean something like this:
1 2 3 4
string response;
cin >> response;
if (response == "yes")
// do something...