循环C++中的分段故障

Segmentation Fault in loops C++

本文关键字:分段 故障 C++ 循环      更新时间:2023-10-16

我遇到了一个分段错误的问题。

这是代码:

string CipherMessage::VigDecipher(string key)
{
    int keyValue;
    int charValue;
    string textInit = m_text;
    // 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"};
    // keyValues contains the values of each term of the multi-character key.
    int keyValues[6];
    // Enters the keyValues into the array.
    for (int i=0; i<key.length(); i++){
        for (int j=0; i<=25; j++){
            if (key[i] == ALPHABET[j])
                keyValues[i] = j;
        }
    }
    return m_text_new;
}

它只是给了我分段的错误。

我猜这一行就是问题所在:

for (int j=0; i<=25; j++){

注意,字符i不是字符j