Help Isolating Individual Words in a String

I'm writing a Pig Latin translator just for fun and the learning experience and I'm having trouble isolating individual words in a string so I can translate them. Well, I should say I have no idea where to start! Here's my code. So far, it just reads the string to be translated and outputs it. Pretty pitiful, I know.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string str;	
	cout << "What would you like to translate? ";
	getline (cin, str);
	cout << str << endl;

	return 0;
}


So how do I isolate individual words? And if you can help it, please don't tell me how to translate them after I've isolated them. I want to figure that part out for myself.
cin does this. It can be annoying at times, but for your purpose, it should work beautifully. Instead of using getline, use cin. It reads one word at a time, seperated by a space. Simply put this in a while loop and it will read an entire line, one word at a time.

1
2
3
4
5
6
7
string wordInput="";

while (wordInput!="end"){
cin>>wordInput;
//Do something with the word
cout<<wordInput<<endl;//endl places a new line after each word fetched.
}
OK, thanks, I'm not sure if I completely understand yet, but I'll just try it and see what happens.
Topic archived. No new replies allowed.