0
我不知道如何解決它。它完成這項工作,一切看起來不錯,但在加密結束時崩潰。 這可能是最後一個標誌。轉錄密碼加密程序崩潰
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main()
{
string text = "This is a sample text that i want to encrypt";
int d = text.length();
int n = ceil(sqrt(d));
string encrypted[n * n];
int i = 1;
int pos = 1;
while(i <= n)
{
int j = 0;
while(j < n)
{
encrypted[pos] = text[i + j * n - 1];
cout << text[i + j * n - 1] << " ";
pos++;
j++;
}
cout << endl;
i++;
}
for(int i = 0; i < d; i++)
cout << encrypted[i];
return 0;
}
檢查超出範圍的訪問權限,並且'string encrypted [n * n]'是可變長度數組,它不受官方C++標準支持。改爲使用'std :: vector'。 –
vsoftco