Question Details

No question body available.

Tags

c++ string

Answers (1)

April 18, 2025 Score: 5 Rep: 81 Quality: Medium Completeness: 60%

The issue here is likely due to how std::isalnum behaves with char types. Specifically, if char is signed on your system (which it is by default on many compilers), and you input a character with a negative value (e.g. extended ASCII), you're invoking undefined behavior.

This can lead to isalnum() incorrectly returning true for non-alphanumeric input.

One way to fix this is to cast the character to unsigned char before passing it to isalnum:

if (std::isalnum(static_cast(inTest))) { std::cout