Need if statement help with a string variable

I am trying to make a program that asks for an answer that is a string, however I cannot make it recognize the correct answer. Any help would be appreciated.

Thank you in advanced!

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])

string answer;

cout << "Stomy = ";
cin >> answer;

if (answer == "new opening")
cout << "Correct!";
else if (answer != "new opening")
cout << "Incorrect :(" << endl;

Last edited on
if you use cin to input a string, it stops when it finds whitespace so you'll need to use getline, like so:

string str;
getline(cin, str);
Last edited on
Ah i see, that helps a ton! thank you very much!
Topic archived. No new replies allowed.