0

I am attempting to iterate over a string to find punctuation and then remove the punctuation from the string. I am able to locate the punctuation just fine but for some reason when I try to erase the punctuation, the string becomes unusable for the rest of my code.

std::string punct;
for(std::string::iterator it = oneWord.begin(); it != oneWord.end(); it++)
{
    if(ispunct(*it))
    {
        punct = *it;
        oneWord.erase(*it);
    }
}

The above segment compiles but the string "oneWord" does not function the same way as if I did not erase any of it.

EDIT:

So i attempted to try this

                    std::remove_copy_if(oneWord.begin(), oneWord.end(),
                    std::back_inserter(punct), //Store output
                    std::ptr_fun<int, int>(&std::ispunct)

but am still having the smae issue with it not removing the punctuation. Also someone mentioned (ill comment the user) in the comments to add

std::string punct( iterator_from_remove_if, oneWord.end()) 

before attempting to erase it. This does not compile. where exactly should I add it? Thank you all for the suggestions so far.

C.Mock
  • 69
  • 8

0 Answers0