我一直在与我认为可能是一个简单的C++问题奋斗了几个小时,我真的可以使用一些帮助。这里是我想要做什么:C++ - 或字符串比较不断抛出布尔错误
void setRarity(std::string inRarity)
{
if (inRarity == "c" || inRarity == "C" || inRarity == "Common" || inRarity = "common")
{
rarity = "common";
}
//additional else-if statements following the same type of syntax as above
return;
}
但我不断收到错误,当我尝试编译(在Ubuntu使用G ++):
In file included from main.cpp:6:0:
class_Card.cpp: In member function ‘void Card::setRarity(std::string)’:
class_Card.cpp:210:68: error: no match for ‘operator||’ (operand types are ‘bool’ and ‘std::string {aka std::basic_string<char>}’)
if (inRarity == "c" || inRarity == "C" || inRarity == "Common" || inRarity = "common")
^
class_Card.cpp:210:68: note: candidate is:
class_Card.cpp:210:68: note: operator||(bool, bool) <built-in>
class_Card.cpp:210:68: note: no known conversion for argument 2 from ‘std::string {aka std::basic_string<char>}’ to ‘bool’
'='应该是'==' – Biffen
@Biffen:就是这样!盯着屏幕的几个小时,我没有注意到我错过了一个等号!谢谢! – XSSerra
嗯,第二个片段有==和parens,为什么不是一个答案Biffen,让人们不要试图回答 –