isdigit raises a debug assertion when entering £ and ¬

后端 未结 2 1932
予麋鹿
予麋鹿 2020-12-21 21:30

The below code works for every character I type in except for £ or ¬.

Why do I get a \"debug assertion fail\"?

#include <         


        
2条回答
  •  心在旅途
    2020-12-21 21:43

    The microsoft docs say:

    The C++ compiler treats variables of type char, signed char, and unsigned char as having different types. Variables of type char are promoted to int as if they are type signed char by default, unless the /J compilation option is used. In this case they are treated as type unsigned char and are promoted to int without sign extension.

    And they also say:

    The behavior of isdigit and _isdigit_l is undefined if c is not EOF or in the range 0 through 0xFF, inclusive. When a debug CRT library is used and c is not one of these values, the functions raise an assertion.

    So char is per default signed, which means as those two characters are not ASCII they are negative in your ANSI charset, and thus you get the assertion.

提交回复
热议问题