Check for multiple values when using comparison operators

后端 未结 4 1341

I\'ve always been under the impression that for any comparison statement, i.e. X == Y or X != Y is the format, and you chain statements together with <

4条回答
  •  一个人的身影
    2021-02-19 16:21

    There's no clean way to do what you ask in C++.

    What trips many people up is that X == (Y || Z) may be a legal expression and the compiler will not complain. It will just be a bug. Each C++ statement must evaluate to true/false on its own and the operators just string them together. What you're suggesting would require some intrinsic list structure. Many languages have that (like Python), but C++ does not.

提交回复
热议问题