while(!infile2.eof())
{
size_t found;
string temp2, store, wordtobold;
string command1 ("bold");
size_t prev_pos = 0, pos = 0;
getline(infile2, temp2);
store += temp2;
found=store.find(command1);
if (found!=string::npos)
wordtobold = store.substr (found+4);
while( (pos = wordtobold.find(' ', pos)) != string::npos )
{
string wordtotag( wordtobold.substr(prev_pos, pos-prev_pos) );
cout << wordtotag;
prev_pos = ++pos;
}
}
Here is my string,
temp2: How are you
wordtobold: are you
i want to use a while loop to check every word in wordtobold,
and my expected output should be:
are
you
But what i got from the above code is only
are
how can i output the word "you" ?