Hey everyone,
I'm trying to remove all punctuation from a string of characters. Here is the part of the code that I'm using to remove the punctuation from the string (string1 being the string).
for (int i =0; string1[i]; i++)
{
if(ispunct(string1[i]))
string1.erase(i,1);
}
It is removing punctuation perfectly fine and leaving behind no whitespace (which is what I want) except for when there are two punctuation marks next to each other. Here is an example of what I mean.
Input string: "This is a sample of input," said I, "and some punctuation remains."
Output: This is a sample of input" said I and some punctuation remains"
It seems when there are two or more punctuation marks next to each other, the one on the farthest right is left in the string. Anyone have any idea why this is? Thanks