That should be pretty easy to test yourself:does string variable types not hold spaces
Code:string str; str = "hello world"; cout<<str<<endl;The extraction operator>> is for reading what's called "formatted input", i.e. input that is grouped into words. It is programmed to start reading and skip any leading whitespace(spaces, tabs, newlines) until it finds some input, then it continues reading input until it hits the first trailing whitespace, and then it stops reading. Therefore, the result is it reads in groupings of characters without any of the spaces, tabs, or newlines between words.or does the >> what casue it not to be able to have spaces?
If you want to read in a whole line of data, spaces and all, use getline().
For char arrays:
char str[30];
cin.getline(str, 30);
//reads 29 chars max or until a newline is reached.
//Last spot is saved for a '\0' char
For strings:
string str;
cin.getline(str, '\n'); //WRONG
//SHOULD BE(as per elad's subsequent post):
string str;
getline(cin, str);