Problem gelöst: StringVariable [Position] (in diesem Fall Word [e]) gibt einen Wert aus, der als Char-Variablentyp und nicht als Zeichenfolgevariablentyp definiert ist. Danke Ihnen allen für Ihre Hilfe!String Comparison Issue (C++)
Wenn ich meinen Henker Spiel laufen bekomme ich folgende Fehlermeldung:
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
ich im Code kommentiert, wo diese Fehler Punkte auf und im Zusammenhang mit dem Problem in den Funktionen kopiert. Die Funktionen wurden dann in der main() - Funktion ausgeführt, um den Code zu vereinfachen.
Dieser Abschnitt des Codes soll prüfen, ob die Schätzung gleich dem Buchstaben im Wort ist. Lassen Sie mich wissen, wenn ich weitere Erklärungen geben muss.
Verwandte Code:
#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;
}
Was 'G' soll sein? –
Kannst du nicht ein [MCVE] präsentieren? – IInspectable
@Guillaume Racicot G ist ein Buchstabe, den der Benutzer eingibt –