C ++' ==':没有来自' int' to' std :: string'

时间:2016-11-05 10:11:01

标签: c++

我正在进行一项任务,到目前为止,我正在询问用户是否想先去。我想检查他们的输入,以确保它匹配我想要的两个值。

我在使用Visual Studio时收到有关转换的错误,例如:

' ==':没有来自' int'到' std :: string'

没有操作员" =="匹配这些操作数

非常感谢任何支持。

3 个答案:

答案 0 :(得分:7)

你的问题在于:

if (turnChoice == 'yes' || turnChoice == 'no')

C ++和C表示带有单引号的单个字符,而不是字符串。因此,编译器尝试将单引号转换为整数值。您必须对字符串文字使用双引号。所以将上面的行改为:

if (turnChoice == "yes" || turnChoice == "no")

答案 1 :(得分:2)

问题在于:if (turnChoice == 'yes' || turnChoice == 'no') 您应该在字符串周围使用双引号,例如:if (turnChoice == "yes" || turnChoice == "no")

答案 2 :(得分:2)

补救措施很简单:您需要将select * from TEST order by case when Description not like '%[0-9]%' then 1 else 0 end, Description $("input").keypress(function(){ //on each keypress in input this function will be executed, calculate your vibration for letters here and append the result in the result field }); 更改为'yes''no',因为后两者是字符串文字使用隐式的nul-terminator。

但是让我们考虑编译器发出错误的原因。

单引号用于表示字符文字。令人惊讶的是,允许实现允许包含 more 而不是"yes"的字符文字:

C11 ++标准,§2.14.3/ 1 - 字符文字

  

包含多个c-char的普通字符文字是a   多字形文字。多字符文字的类型为int和   实现定义的价值。

因此"no"char的类型为'yes'。由于'no'类不允许分配到int类型,因此会发出您看到的错误。