Input problem

Hey there guys, I am facing a problem
I have successfully implemented my c++ code to manipulate a string,
but the problem is that I want my program to ask the user to enter a bunch of strings,the problem is that I want all those strings to be entered all at one time, with a space between each word, and if the user doesnt want to manipulate the word then he will just press enter.


The problem I am facing is that I dont know how could I possibly cin all those words together and store them, when I dont even know how many words the user will enter.

The other problem is that I dont know how to let the program break, when the user just presses enter???


If u could provide any help I would be really grateful ;)
This is not entirely clear.
I want to break out of a loop if the user presses the "enter" button. How could that be possible
Last edited on
Do you want something like this:

1
2
3
4
5
6
7
8
vector< string > vStr;
string str;

while( getline( cin, str ) )  // Either stops on EOF
{
    if( str.empty() ) break;  // or stops on empty string
    vStr.push_back( str );
}

Is there anyway that could be possible without using the vector string.. Thanks anyways
Yes, just tack it on to the end of the sum string.
1
2
3
4
5
6
7
string all_words, s;

while (getline( cin, s ))
  {
  if (s.empty()) break;
  all_words = all_words + " " + s;
  }

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