if( !( *it >= 0x41 || *it <= 0x5A ) && !( *it >= 0x61 || *it <= 0x7A ) )
I tried something like this but it doesn't catch anything.
if( !( *it >= 0x41 || *it <= 0x5A ) && !( *it >= 0x61 || *it <= 0x7A ) )
I tried something like this but it doesn't catch anything.
There is the standard library function std::isalpha
for this:
if( !std::isalpha(static_cast<unsigned_char>(*it))
It tests if a character is a letter or not. Note that the cast before calling std::isalpha
is indeed needed.
Consider the expression
*it >= 0x41 || *it <= 0x5A
This expression is true
for any value at all. Consider a simpler version:
x > 5 || x < 10
Every value x
is either greater than 5 or less than 10 (or both). There's no value for which neither of those tests are true.
You probably want
*it >= 0x41 && *it <= 0x5A
which checks whether your character is both greater than 'A' and less than 'Z'. You'll have to make similar changes to the other parts of your test, too.
Of course, a better way is to use the standard isalpha()
function, but changing to use that won't help you learn anything about why your given code doesn't work.