c++c++11isspace

Debug assertion failed with std::erase


I'm writing a program to parse a logfile, and decided to be as C++ about that as possible and I got hit with debug assertion for this line -

sLine.erase(remove_if(sLine.begin(), sLine.end(), isspace), sLine.end()); 

Assertion that character must lie between -1 and 256

Which seems to because of a character of value -80 at like, 2000th line of the logfile.

The offending character

So, I tried this

sLine.erase(remove_if(sLine.begin(), sLine.end(), [](char c) { return c >= -1 && c<=255; }), sLine.end());

But this code snippet gets stuck with no explanation.

So, finally I have three questions -

  1. Why is that debug assertion is required?
  2. What is the reason for the second code snippet to fail?
  3. Any workarounds you could suggest?

Thanks for any help!


Solution

    1. It is an assertion to test that the character argument is not out of range. The character '°' (-80) is not an ascii character so it is out of range.
    2. I am not sure what you mean, this code snippet removes all ascii characters.
    3. The following code will work if you just want to erase space characters

      sLine.erase(std::remove_if(sLine.begin(), sLine.end(), [](char c) { return (c == ' '); }), sLine.end());