+ 4
Already figured out? well, just in case it's not, here's an example:
#include <string> // <-- Don't forget this header
#include <iostream>
using namespace std;
int main()
{
string stringVar;
// Use the following to accept multi words
// where spaces is allowed e.g:
// "Donald Duck"
getline(cin, stringVar);
cout << stringVar << endl;
// Use the following to accept single word
// no space acceptable here e.g:
// "Donald"
cin >> stringVar;
cout << stringVar;
return 0;
}
Mind though, that mixing these two approaches in a code may cause you trouble, lookup on how to use cin.ignore() to clear the buffer off before continuing with next input, or we'll risk getting unexpected data : )
Hth, cmiiw