#last word of string is not processed

12 messages · Page 1 of 1 (latest)

safe holly
#

My code is supposed to take in a string with multiple words and return a set with unique word

(function "clear token" returns string without any punctuations or empty if no letter in word)

However if the word is very long, it doesn't take in last word of a string. Does anyone know what I did wrong?

subtle brambleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

static cargo
#

You can extract whole words from a string far easier using istringstream

set<string> gatherTokens(const string& text) {
    set<string> tokens;
    string token;
    
    istringstream str(text);
    while (str >> token)
    {   
         tokens.insert(token);
    }
}
safe holly
static cargo
#
while (ispunct(s.back())
{
  s.pop_back();
}
safe holly
#

!solved

subtle brambleBOT
#

Thank you and let us know if you have any more questions!

#

[SOLVED] last word of string is not processed

static cargo
#

I am not sure about removing punctuation from the front though.
There doesn't appear to be a string::pop_front() method.

#

Perhaps:

while (ispunct(s.front())
{
  s.erase(s.begin());
}
subtle brambleBOT
#

@safe holly

This question thread is being automatically marked as solved.