Frequently, you may need to isolate words in a phrase. In this example, we'll use substr to carry out this task.
Another use of substr
string phrase = "Now is the oppurtunity to claim money";
string word;
int i, space;
phrase+=" ";//add space to end of phrase
while(phrase.length()>0)
{
space = phrase.find();//find position of the first space in phrase
word = phrase.substr(0,space);
//process word here and then go to next word
cout<<word<<endl;
phrase = phrase.substr(space+1);//create new phrase with first word chopped off
}//end while phrase
munyu 0 Newbie Poster
HackWizz 0 Junior Poster in Training
zandiago 115 Nearly a Posting Maven Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.