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