0

Possible Duplicate:
Extract multiple words to one string variable
changing the delimiter for cin (c++)

I'm having trouble using the cin. My code:

cout << "Enter Main Keyword: ";
    cin >> mainKeyword;
    cout << "==========" << endl;

    cout << "Enter Secondary Keyword: ";
    cin >> secondaryKeyword;

When I enter "key word" (without the quotes) for the mainKeyword variable, the program automatically assigns "key" to mainKeyword and "word" to secondaryKeyword, what is the code to get the program to consider two or more strings as one input?

Thanks.

Community
  • 1
  • 1
ARTHUR
  • 19
  • 1
  • 1
  • 4

2 Answers2

2

If you want to read an entire line of input, you use getline:

getline(cin, mainKeyword);
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
0

The default delimiter for cin is whitespace, to change it, see this SO question:

changing the delimiter for cin (c++)

Or use getline and perform any splitting yourself.

Community
  • 1
  • 1
Phil H
  • 19,928
  • 7
  • 68
  • 105