c ++指针崩溃了应用程序

时间:2016-04-13 19:08:43

标签: c++ pointers

此代码是从输入字符串转换为二进制。但是tempPointer函数中的指针dataToCode()正在崩溃应用程序。请指导。谢谢。

int main(void)
{
string text;
    cout << " Enter the text/code you want to convert: ";
    cin >> text;
dataToCode(text); 
}

string* asciiToBinary(string input) {

    string binaryArray[5];

    for (int i = 0; i < input.length(); i++) {

         binaryArray[i] = bitset<8>(input[i]).to_string();
         //cout << binaryArray[i] << endl;
    }
    string* tempPointer = binaryArray;
    for (int i = 0; i < input.length(); i++) {

        //cout << *(tempPointer + i);
    }
    return tempPointer;

}

void dataToCode(string input) {

    string binaryCode[5];

    string* tempPointer = asciiToBinary(input);

    for (int i = 0; i < input.length(); i++) {
        //binaryCode[i] = *(tempPointer + i);
        //cout << binaryCode[i] << endl;
        cout << *(tempPointer + i);
    }

}

0 个答案:

没有答案