在 if 语句中比较字符串时如何修复“'operator==' 不匹配”
How to fix 'no match for 'operator=='' when comparing strings in if statement
尝试使用 if 语句比较字符串但出现运算符错误。我该如何解决这个问题以使语句比较字符串?使用 Code::Blocks 作为编译器。
完整原始代码 Pastebin:https://pastebin.com/DJGqJBwu(由于问题已解决,不再 public)
(注意:原始代码中的大部分评论都是为了实验,总的来说有很多错误我可以稍后再看)
这是我尝试为井字游戏创建的排行榜。我尝试了不同的方法来比较字符串来解决这个问题,例如 .compare.
void admin (string names, int nameW[10], int wins[10], unsigned int a[10]) //called variables from main
{
char repeat = 'y'; //used for function loop
char resetAll; //used elsewhere
int winCount; //used elsewhere
string reset;
string modify; //used elsewhere
string admin; //used elsewhere
cin >> reset;
//Reset
if (reset==names[0])
{
wins[0] = 0;
}
}
构建日志:
error: no match for 'operator==' (operand types are 'std::__cxxll::string {aka std::__cxll::basic_string<char>}' and '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}')
我希望重置变量与名称[0] 变量相同,以便代码可以执行。结果是代码无法构建并且 运行(无法测试程序)。
问题是字符串 "names" 没有声明数组的管理函数参数。
转:
void admin (string names, ...
进入:
void admin (string name[10], ...
尝试使用 if 语句比较字符串但出现运算符错误。我该如何解决这个问题以使语句比较字符串?使用 Code::Blocks 作为编译器。
完整原始代码 Pastebin:https://pastebin.com/DJGqJBwu(由于问题已解决,不再 public)
(注意:原始代码中的大部分评论都是为了实验,总的来说有很多错误我可以稍后再看)
这是我尝试为井字游戏创建的排行榜。我尝试了不同的方法来比较字符串来解决这个问题,例如 .compare.
void admin (string names, int nameW[10], int wins[10], unsigned int a[10]) //called variables from main
{
char repeat = 'y'; //used for function loop
char resetAll; //used elsewhere
int winCount; //used elsewhere
string reset;
string modify; //used elsewhere
string admin; //used elsewhere
cin >> reset;
//Reset
if (reset==names[0])
{
wins[0] = 0;
}
}
构建日志:
error: no match for 'operator==' (operand types are 'std::__cxxll::string {aka std::__cxll::basic_string<char>}' and '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}')
我希望重置变量与名称[0] 变量相同,以便代码可以执行。结果是代码无法构建并且 运行(无法测试程序)。
问题是字符串 "names" 没有声明数组的管理函数参数。
转:
void admin (string names, ...
进入:
void admin (string name[10], ...