如何修复"运算符不匹配=="比较if语句中的字符串时
How to fix 'no match for 'operator=='' when comparing strings in if statement
尝试使用if语句比较字符串,但遇到运算符错误。如何修复此问题以使语句比较字符串?使用代码::块作为编译器。
完整的原始代码粘贴:https://pastebin.com/DJGqJBwu(由于问题已解决,不再公开)
(注意:原始代码中的大多数注释都是为了实验,总的来说有很多错误,我稍后可以查看)
这是一个排行榜,我正试图创建一个Tic-Tac-Toe游戏。我尝试了不同的方法来比较字符串来解决这个问题,比如.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}')
我希望重置变量与names[0]变量相同,以便代码可以执行。结果是代码无法构建和运行(无法测试程序)。
问题是管理函数参数中的字符串"names"没有声明数组。
转弯:
void admin (string names, ...
进入:
void admin (string name[10], ...
相关文章:
- Switch 语句(字符串)一直选择默认值,除非其为零
- 有没有办法在C++将字符串与开关语句一起使用?
- 我如何将 OR 与 if 语句一起使用字符串
- PostgresSQL - SQL Ready 语句与字符串转义,防止 SQL 注入攻击
- C++ 虽然语句不适用于字符串和"or"
- 这两个C++语句连接字符串有什么区别?
- 不能在 if 语句 - c++ 中使用 void func 直接将字符串转换为大写
- 有没有办法我可以在 C++ 中使用 if 语句来说明如果一个字符串不是两个名称的 eqal,它会给出一个输出,ATM i
- 如果语句错误地读取字符串,则始终在第一个条件返回
- 当我的 if 语句在字符串中找到空格时,在无限循环中切换
- 尝试使用 indexOf 创建一个 if 语句来检查字符串是否包含字符.有一点麻烦
- 是否可以对任何语句字符串使用预准备语句?
- 为什么我的 if 语句不适用于 c++ 中的字符串?
- 是什么使这个以'+'开头的字符串添加成为有效的语句?
- scanf() 语句中"%*[^n]"的格式字符串指示什么?分配抑制器 (*) 和否定扫描集 ([^) 如何协同工作?
- 如何比较if语句中的字符串?
- C++字符串和 while 语句的问题
- 与 IF 语句C++的字符串比较?
- if 语句没有比较我的字符串 C++ 中的数值
- If字符串语句