string input;
string code[4];
if (code.find(o) == input.find(o))
{
}
对于这一行,它给了我错误:request for member 'find' in 'code', which is of non-class type 'std::string [4]'
stringinput
和 stringcode
都有string
值。
编译器告诉你这code
是一个字符串数组,所以你需要类似的东西
code[someIndex].find(o) == ....
只需阅读错误:
错误:在'code'中请求成员'find',它是非类类型'std :: string [4]
它告诉你:
code
是类型(这是一个由 4 个对象std::string [4]
组成的数组)std::string
find
您请求的成员函数只需为要调用的字符串选择正确的索引find
或执行循环:
for (int i = 0; i < 4; i++)
if (code[i].find(o) == input.find(o))
// ...
请注意,如果可以,您应该尽量避免使用 C 样式的数组并使用std::array
(自 C++11 起)或std::vector
代替。
错误说明一切,code
是一个数组std::string
比较使用
code[i].find(o)
i
= 循环索引