检查值是否在statation中的范围内 [英] Checking if a value is within a range in if statment

查看:123
本文介绍了检查值是否在statation中的范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面做了:

if( '0' <= infix.at(i)<= '9'){
// some logic
}

编译器给我警告不安全使用类型'bool'在操作。我将其更改为以下内容:

Compiler gave me warning unsafe use of type 'bool' in operation. I changed it to following:

if( '0' <= infix.at(i)&& infix.at(i) <= '9') 

是第一个不允许在C ++中

now it works. Is the first one not allowed in C++??

推荐答案

第一个版本将是

The first version would be evaluated like this:

if( ( '0' <= infix.at(i) ) <= '9' )

获取有关 bool 的警告 - 您将收到 true / false< ='9'感觉。

which is why you get a warning about bool - you wind up with true/false <= '9' which doesn't make sense.

一些语言允许你链接比较运算符,但C ++不是其中之一。

Some languages allow you to chain comparison operators, but C++ is not one of them.

这篇关于检查值是否在statation中的范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆