user3178285
user3178285

Reputation: 151

Why doesn't my compiler like this statement?

This is supposed to return false if a character in the string isn't a letter or an apostrophe. Any idea why it doesn't work? And is there a better way that I can write it? I'm trying to write code like a C++ purist.

for (std::string::const_iterator it = S.begin(); it != S.end(); ++it)
    if ((*it < 'a' || *it >'z') && (*it > 'A' || *it < 'Z') && (*it != ''''))
        return false;

Upvotes: 0

Views: 73

Answers (1)

ruakh
ruakh

Reputation: 183251

I see two mistakes:

  • '''' should be '\''.
  • *it > 'A' || *it < 'Z' should be *it < 'A' || *it > 'Z'.

Upvotes: 7

Related Questions