Doesn't recognize variable value including spaces

Okay, so I'm starting out just now making a simple Q & A program for a class right now, but when I type in the correct if value for "question", it skips right to the "else" ---- but only if there's a space contained in the value. How can I fix this?
Here's the coding:

#include <iostream>
#include <string>
using namespace std;

int main()
{
system("color 0a");
string question;
pstart:
system("cls");
cout << "What is your question?";
cout << endl;
cout << endl;
cout << " :";
cin >> question;
if(question == "space space") //doesn't recognize the value when there's a space inbetween the two words
{
cout << endl << endl << " 42." << endl << endl;
system("pause");
goto pstart;
}
else
{
cout << endl << endl << " Your question is invalid." << endl << endl;
system("pause");
goto pstart;
}
}
cin>> stops reading at the first whitespace character, including spaces. You should use getline(cin, question); instead.
Okay, wow.. thank you so much, I always get caught up on the stuff that should be simple. Works perfect now, I really appreciate the help.
system("pause");
system("cls");//remove all of these
system("color 0a");

you also forgot a return value for your main function.
How to system("pause"): http://cplusplus.com/articles/iw6AC542/
(Sorry the article is messy -- I need to refine it for the new Articles layout)

How to system("cls"): http://cplusplus.com/articles/4z18T05o/

How to system("color 0a"):
http://www.cplusplus.com/forum/general/9974/#msg46705
http://www.cplusplus.com/forum/beginner/10645/#msg49765
http://www.cplusplus.com/forum/beginner/5830/#msg25972
(Sorry there is no Article yet -- someday there will be)

Hope this helps.
Topic archived. No new replies allowed.