c++報錯問題解決方案lvalue required as left operand of assignment

這篇文章主要介紹了c++報錯:lvalue?required?as?left?operand?of?assignment,出現此錯誤原因,是因為,等號左邊是不可被修改的表達式或常量,而表達式或常量不能作為左值,需要的朋友可以參考下

在編程時出現報錯:文章源自四五設計網-http://www.wasochina.com/39184.html

lvalue required as left operand of assignment文章源自四五設計網-http://www.wasochina.com/39184.html

出現此錯誤原因,是因為,等號左邊是不可被修改的表達式或常量。而表達式或常量不能作為左值。歸根結底類似于文章源自四五設計網-http://www.wasochina.com/39184.html

3=b;文章源自四五設計網-http://www.wasochina.com/39184.html

這種錯誤。
而查看代碼發現,是判斷出了問題文章源自四五設計網-http://www.wasochina.com/39184.html

1
2
3
if(!strA.compare(strB)&&!strC.compare(strD)&&n1=n2){
????...
}

由于n1==n2漏寫一個等于號,造成括號內由判斷條件變成了賦值語句:左值=n2。而由!strA.compare(strB)&&!strC.compare(strD)&&n1組成的是一個布爾值常量。顯然是不能作為左值的。文章源自四五設計網-http://www.wasochina.com/39184.html

到此這篇關于c++報錯:lvalue required as left operand of assignment的文章就介紹到這了文章源自四五設計網-http://www.wasochina.com/39184.html 文章源自四五設計網-http://www.wasochina.com/39184.html

我的微信
微信掃一掃
weinxin
我的微信
惠生活福利社
微信掃一掃
weinxin
我的公眾號
 
  • 本文由 四五設計網小助手 發表于 2024年1月26日10:24:25
  • 轉載請務必保留本文鏈接:http://www.wasochina.com/39184.html

發表評論

匿名網友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖動滑塊以完成驗證