I have a string that consists of:
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.
I have the following code that is supposed to strip this string of all punctuation. The test variable is my string:
if(std::ispunct(test[test.length()-1]))
{
test.erase(test.length()-1, 1);
}
However when I output this string again after this function I have the following:
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity
For some reason the ispunct function is able to strip the period but not the comma. Why is it behaving in this manner? Thanks in advance.
Well, you’re only doing this for
test[test.length()-1](the last character in the string). There’s no comma there, just the period.