1

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!

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524

1 Answers1

1
  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());

0xBADF00
  • 1,028
  • 12
  • 26
  • 2. Oh, yeah, I should have reversed the signs. Stupid of me. 3. Works fine, that assertion was thrown by isspace, not by standard library, as I thought. Thank you! – Vivek Subramanian Jun 14 '17 at 07:11