我正在研究一个凯撒解密项目,并且在 CaesarDecipher 函数中,我在编译时不断收到此错误:
错误:在 'textInit.std::basic_string<_CharT, _Traits, >_Alloc>::operator[] [with _CharT = char, _Traits = std::char_traits, _Alloc >= std:: 中不匹配 'operator=='分配器](((long unsigned int)i)) == 字母表[j]'</p>
这是该函数的代码:
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;
}
任何人都可以帮忙吗?