C++ Strip non-ASCII Characters from string

后端 未结 3 1020
小蘑菇
小蘑菇 2020-12-16 03:52

Before you get started; yes I know this is a duplicate question and yes I have looked at the posted solutions. My problem is I could not get them to work.

b         


        
3条回答
  •  情歌与酒
    2020-12-16 04:40

    At least one problem is in your invalidChar function. It should be:

    return !isprint( static_cast( c ) );
    

    Casting a char to an unsigned is likely to give some very, very big values if the char is negative (UNIT_MAX+1 + c). Passing such a value toisprint` is undefined behavior.

提交回复
热议问题