二进制表达式的操作数无效?
Invalid operands to binary expressions?
我正在尝试使用下面提供的代码比较字母两个字符串,但不断收到此错误。
此代码是我尝试的代码
#include <vector>
#include <string>
std::vector<int> solve(std::vector<std::string> arr){
std::string underCase = "abcdefghijklmnopqrstuvwxyz";
std::string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int counter = 0;
for(int i=0; i < arr.size(); i++){
(underCase[i] == arr[i]) ? counter++ : 0;
(upperCase[i] == arr[i]) ? counter++ : 0;
}
return counter;//your code herw
};
这是我得到的错误输出,但我似乎不明白。
main.cpp:13:19: error: invalid operands to binary expression ('int' and 'value_type' (aka 'std::__1::basic_string<char>'))
(underCase[i] == arr[i]) ? counter++ : 0;
~~~~~~~~~~~~ ^ ~~~~~~
main.cpp:14:19: error: invalid operands to binary expression ('int' and 'value_type' (aka 'std::__1::basic_string<char>'))
(upperCase[i] == arr[i]) ? counter++ : 0;
~~~~~~~~~~~~ ^ ~~~~~~
main.cpp:16:10: error: no viable conversion from returned value of type 'int' to function return type 'std::vector<int>'
return counter;//your code herw
^~~~~~~
在这里:
underCase[i] == arr[i]
您正在尝试将char
(std::string
的元素(与整个std::string
(std::vector<std::string>
的元素(进行比较。
似乎您可能想要:
underCase[i] == upperCase[i]
或类似的东西:
underCase[?] == arr[i][?]
此外,最好使用正确的if
s 而不是条件运算符:
if (upperCase[i] == upperCase[i])
counter++;
- 返回类型与函数的返回类型不匹配。 整数和矢量
- 您没有在形式参数中模板化向量的类型。
修复这两件事可以让它在我的机器上运行。无论目的是什么。
相关文章:
- 类型"int"和"const char [15]"到二进制"运算符<<"的无效操作数^
- 二进制表达式 cout 问题的无效操作数
- 二进制'operator+' 'int*'和'int*'类型的无效操作数
- 'const char [26]' 和 'LPSTR ' 类型的无效操作数
- 如何修复"二进制表达式的无效操作数"?
- 如何将无效操作数修复为二进制表达式
- 错误:二进制表达式('float' 和 'float')返回的无效操作数 (x & (1 << 31)) == 0
- 加密注释C++具有无效操作数的编译错误
- 如何将无效操作数修复为带有字符串的二进制表达式?
- 模板 &&运算符中的无效操作数+
- 类型别名和运算符<<使用 ostream_iterator 重载会导致无效操作数
- 类型为"double" snd const char [3]' 到二进制'operator<<'的无效操作数
- 二进制表达式的语义问题无效操作数("双精度"和"双精度")
- 'double' 和 'const char [2]' 到二进制"运算符!="的无效操作数|
- 具有重载运算符<<的无效操作数
- 'double' 和 'double' 类型的无效操作数
- 整数和无效操作数中的小数*已更新
- 二进制'operator<<' 'const char [6]'和'const char [3]'类型的无效操作数
- 将算法c++的无效操作数替换为二进制表达式
- 'char*'和'const char [2]'到二进制'operator+'类型的 C++ 无效操作数