简体   繁体   中英

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;

I see two mistakes:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM