List of Words

I am trying to write a program where the user inputs a sentence and the program outputs each word on a separate line. I know I need a loop but I don't know how to set it up?
Show us what you have so far and we'd be happy to help.
you try to this code !
1
2
3
4
5
6
7
8
 cout<<" Enter the number which you want to chosse : ";
 cin>>chosse;
 do {
	 case 1: cout<< " doing something 1  which you want to do " ;
	 case 2 : cout<< " doing something 2 .....";
	 ........
	 default : break;
 while ( chosse < 1 || chosse > n );
Last edited on
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
string sentence;
int length;

cout << "Enter a sentence:\n";
getline(cin, sentence);

int x = sentence.find(" ");
int y = sentence.find(" ", x);

cout << sentence.substr(0, x) << endl;
while(??????)
{
cout << sentence.substr(x+1, y-1) << endl;
int x = sentence.find(" ");
}

system("PAUSE");
return EXIT_SUCCESS;
}
That's okay. How about writing a replace function. Just replace all of the spaces with '\n' and then output your string.
That sounds great, but this is for a class and we haven't learned about replace functions yet so I wouldn't be able to use one. I like the idea of it though.
"haven't learned replace functions"

Why would you let your class hold you back?!?!?! Just learn man, and grow and gain the skills and power to do everything on your own and create!!
Topic archived. No new replies allowed.