Question about strings: multiple words input. [SOLVED]

I have a problem involving strings and basic c++ functions. In one point of my program user is asked to input one or more sentences. And program's function is to put it in one string for further analysis.
The problem lies here: when multiple words are put in by user, every space ends the string and saves the following data for next inputs - useful way of dividing data for some programs, but not for this one.
And here's the question: is there any simple way of solving this problem?
Thanks in advance for anyone who solves it.
Last edited on
you can try this:
getline(cin,X)

that way, instead of taking only the first word, it should take the whole line
Where X would be the name of the string, right? Also, line taken as to the first line breaker (\n or endl)?
yes, X would be the string, and it would take all words until pressing enter.

For example, if u ask somebody to write their full name they'd have to write "Jonh Lalala Smith" and hit enter
Ok, I'll try this. Thanks :)
-------------------------------------------------------------------------------------------------
There seems to be a problem with it. Here's the part of the code:

int it=0; string choice[10];
-------------------------------------
do{
cout<<"Insert choice number"<<it+1<<".\n";
getline(cin,choice[it]);
it++;}while(it<10)
.
It skips choice no. 1 and starts from the second one. Do you have any idea why is it like this?
Last edited on
Topic archived. No new replies allowed.