【发布时间】:2014-06-28 14:03:58
【问题描述】:
说明:
我正在尝试编写一个有趣的基本程序,该程序将输入一个字符串/短语,然后对它进行异或加密,最后计算出加密的短语。我正在使用 Mac,所以我将使用 xcode 编译并在终端中运行它。
问题:
我在输入可以异或加密的字符串时出错,请参见下面的代码:
代码:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string mystr;
cout << "What's the phrase to be Encrypted? ";
//getline (cin, mystr);
char string[11]= getline (cin, mystr); //ERROR: Array must be initialized with brace-enclosed initializer
cout << "Phrase to be Encrypted: " << mystr << ".\n";
char key[11]="ABCDEFGHIJ"; //The Encryption Key, for now its generic
for(int x=0; x<10; x++)
{
string[x]=mystr[11]^key[x];
cout<<string[x];
}
return 0;
}
帮助:
请指出并解释或提供示例我收到上述错误代码的原因。
【问题讨论】:
标签: c++ encryption xor