我想使用XOR方法制作加密器/解密器。我已经在Console C++中完成了这个工作,并且我是VC++的新手,所以我希望你能帮助我。 加密的工作原理是这样的:Visual C++奇怪的编译器错误
key = 3
x = 5 // The item being encrypted
encryptedx = x^key // the "^" is XOR
所以,现在,我希望把它在VC++,使这更好看的控制台窗口。 在VC++的设计视图中,我有两个富文本框,编辑框和一些按钮来启动过程。 这听起来很容易,但是我得到这些错误:
------ Build started: Project: Encryptor, Configuration: Debug Win32 ------
1> Encryptor.cpp
1>c:\users\**********c*********ncryptor\encryptor\Form1.h(264): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(707): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(std::basic_string<_Elem,_Traits,_Ax> &&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(762): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(767): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(772): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::string, System::String ^)'
1>c:\*******gl\*****cryptor\encryptor\Form1.h(281): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(707): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(std::basic_string<_Elem,_Traits,_Ax> &&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(762): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(767): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(772): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::string, System::String ^)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这里是代码:
#include <string>
#include "crypFunc.cpp"
int key = 0;
char tempChar;
int stringLenght = 0;
string strBuffer = "";
using namespace std;
//
//
//
//
//
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
if(KeyBox->Text)
{
key =Convert::ToInt32(KeyBox->Text);
numericUpDown1->Value = key;
}
}
//
//
//
//
private: System::Void EncryptButton_Click(System::Object^ sender, System::EventArgs^ e)
{
EncryptedBox->Text = "";
strBuffer = DecryptedBox->Text;
stringLenght = strBuffer.size();
if(strBuffer.size() && key)
{
for(int i = 0; i < stringLenght; i++)
{
tempChar = encrypt(strBuffer[i], key);
EncryptedBox->Text = EncryptedBox->Text + tempChar;
}
}
}
private: System::Void DecryptButton_Click(System::Object^ sender, System::EventArgs^ e)
{
DecryptedBox->Text = "";
strBuffer = Convert::ToString(EncryptedBox->Text);
stringLenght = strBuffer.size();
if(strBuffer.size() && key)
{
for(int i = 0; i < stringLenght; i++)
{
tempChar = decrypt(strBuffer[i], key);
DecryptedBox->Text = DecryptedBox->Text + tempChar;
}
}
}
};
}
我真的希望你们中的一些可以和想帮助我。
嘿。我理解你的答案,并且在源代码中设置了它,但它仍然无效。 你能告诉我你将如何解决在System :: Void EncryptButton_Click这个问题? – Janman 2011-02-08 19:28:42