dimanche 29 mars 2015

No match for 'operator==' in function

I am working on a caesar decipher project, and in the CaesarDecipher function I keep getting this error when compiling:



error: no match for ‘operator==’ in ‘textInit.std::basic_string<_CharT, _Traits, >_Alloc>::operator[] [with _CharT = char, _Traits = std::char_traits, _Alloc >= std::allocator](((long unsigned int)i)) == alphabet[j]’



Here is the code for that function:



string CipherMessage::CaesarDecipher(string key)
{
int keyValue;
int charValue;
string textInit = m_text;
string textFinal;
// Initializes an array containing the alphabet. A=index 0, B=index 1, etc
string alphabet[26] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","\
O","P","Q","R","S","T","U","V","W","X","Y","Z"};

for (int i=0; i<=25; i++){
if (alphabet[i] == key)
keyValue = i;
}
for (int i=0; i<=textInit.length(); i++){
for (int j=0; j<=25; j++){
if (textInit[i] == alphabet[j]) // Error occurs here
charValue = j;
}
charValue = (charValue+keyValue)%26;
for (int j=0; j<=25; j++){
if (charValue == j)
textFinal += alphabet[j];
}
}
cout << "Final " << textFinal << endl;

return textFinal;
}


Can anyone help?


Aucun commentaire:

Enregistrer un commentaire