"左值要求作为分配及QUOT的左操作数;错误 [英] "lvalue required as left operand of assignment " error

查看:283
本文介绍了"左值要求作为分配及QUOT的左操作数;错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code生产

if( c >= 'A' && c <= 'Z'  || c = " " || c = ",") {

我以为我在写这个毛病,有什么不好?我怎么会写这是否正确?
我想AP preciate任何帮助! :)

I assume I'm writing this wrong, what is wrong? and how would I write it correctly? I would appreciate any help! :)

感谢。

推荐答案

您应该使用单引号字符和平等做双等号(否则它改变c的值)

You should use single quotes for chars and do double equals for equality (otherwise it changes the value of c)

if( c >= 'A' && c <= 'Z'  || c == ' ' || c == ',') {

此外,你可能会考虑这样的事情,让您的布尔逻辑更加清晰:

Furthermore, you might consider something like this to make your boolean logic more clear:

if( (c >= 'A' && c <= 'Z')  || c == ' ' || c == ',') {

虽然你的布尔逻辑结构的工作原理等同(安培;&功放;在需要precedence ||),这样的事情可能会发觉你在未来

Although your boolean logic structure works equivalently (&& takes precedence over ||), things like this might trip you up in the future.

这篇关于&QUOT;左值要求作为分配及QUOT的左操作数;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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