问题迎刃而解:StringVariable [位置](在此情况下字[E])输出被定义为char变量类型,而不是我的预期它字符串变量类型的值。感谢大家的帮助!字符串比较版本(C++)
当我跑我的刽子手游戏,我得到以下错误:
Error 2 error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
4 IntelliSense: no operator "!=" matches these operands
3 IntelliSense: no operator "==" matches these operands
我在这个错误点,并在相关问题的功能复制的代码注释。然后函数在main()函数中运行以简化代码。
的这部分代码是为了检查猜测是否等于字的信。让我知道是否需要提供进一步的解释。
相关代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//Functions
void GrabWord();
void DiscoverLet();
void guess();
//Variables
int NumL, Fl, F, count[10];
string G, Word;
//Grab Word from .txt and define NumL
void GrabWord()
{
//Grab Random Line from .txt
//Random Line >> Larray
Word = "short";
NumL = Word.size();
}
//Checks if Guess matches any letters
void DiscoverLet()
{
for(int e = 0; e < NumL; e++)
{
//Error Points to the following two comparisons
if(G == Word[e])
{
count[e] = 1;
}
else if(G != Word[e])
{
Fl++;
}
else
{
cout << "Error: DiscoverLet(), G to Word[]\n";
}
}
if(Fl == NumL)
{
F = F + 1;
}
Fl = 0;
}
G应该是什么? –
你不能提出[mcve]吗? – IInspectable
@Guillaume Racicot G是用户输入的字母 –