gpt4 book ai didi

c++ - 将 C++ builder 6 项目转换为 C++ builder 2010

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:59:18 26 4
gpt4 key购买 nike

我有一个用 c++ builder 6 编写的简单项目。它是关于加密 RSA 算法的。想要转换为 c++ builder 2010,但它给出了错误

例如主工程源码

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "UTForm.h"
#include "UTRSA.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
randomize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRSA a(Edit4->Text.ToInt());

char* tmp = a.KeyModul;
Edit1->Text = AnsiString(tmp);
tmp = a.OpenKey;
Edit2->Text = AnsiString(tmp);
tmp = a.SecretKey;
Edit3->Text = AnsiString(tmp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TNumber n(Edit1->Text.c_str());
TNumber e(Edit2->Text.c_str());
TNumber d(Edit3->Text.c_str());

THexString text;
text.AsCharString = Edit5->Text;

if (Edit3->Text != "")
{
TRSA a(n,e,d,Edit4->Text.ToInt());
a.PlainText = text;
Edit6->Text = a.CryptedText.AsHexString;
}
else
{
TRSA a(n,e,Edit4->Text.ToInt());
a.PlainText = text;
Edit6->Text = a.CryptedText.AsHexString;
}
}

//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
TNumber n(Edit1->Text.c_str());
TNumber e(Edit2->Text.c_str());
TNumber d(Edit3->Text.c_str());

THexString text;
text.AsHexString = Edit6->Text;

if (Edit3->Text != "")
{
TRSA a(n,e,d,Edit4->Text.ToInt());
a.CryptedText = text;
Edit8->Text = a.PlainText.AsCharString;
}
else
{
TRSA a(n,e,Edit4->Text.ToInt());
a.CryptedText = text;
Edit8->Text = a.PlainText.AsCharString;
}
}
//---------------------------------------------------------------------------

错误是:

Build
Checking project dependencies...
Compiling RSA.cbproj (Debug configuration)
[BCC32 Warning] UTHexString.cpp(92): W8012 Comparing signed and unsigned values
[BCC32 Warning] UTHexString.cpp(92): W8012 Comparing signed and unsigned values
[BCC32 Warning] UTForm.cpp(29): W8057 Parameter 'Sender' is never used
[BCC32 Error] UTForm.cpp(33): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(34): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(35): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Warning] UTForm.cpp(52): W8057 Parameter 'Sender' is never used
[BCC32 Error] UTForm.cpp(57): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(58): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(59): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Warning] UTForm.cpp(76): W8057 Parameter 'Sender' is never used
Failed
Elapsed time: 00:00:01.5
Project Import
Upgrading project "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.bpr"
Reading "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.bpr"
Upgraded to "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.cbproj"

我认为 C++ Builder 2010 具有默认的 unicode 支持,这就是为什么或者我错了?当我查看 TNumber 构造函数时,它具有以下内容:

//---------------------------------------------------------------------------
#ifndef UTNumberH
#define UTNumberH
//---------------------------------------------------------------------------
#include <assert.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>

class TNumber
{
private:
TNumber multdigit(int) const;
TNumber mult10(int) const;

char *vlstr;
int vlen;
int vlsign;

public:

TNumber(const char* = NULL);
TNumber(int);
TNumber(const TNumber &);
~TNumber();

operator int() const;
operator long() const;
operator double() const;
operator char*() const;

const TNumber& operator=(const TNumber&);

TNumber operator - () const;
TNumber operator ++ ();
TNumber operator ++ (int);
TNumber operator -- ();
TNumber operator -- (int);

TNumber operator += (const TNumber &);
TNumber operator -= (const TNumber &);
TNumber operator *= (const TNumber &);
TNumber operator /= (const TNumber &);
TNumber operator %= (const TNumber &);

friend TNumber operator + (const TNumber &, const TNumber &);
friend TNumber operator - (const TNumber &, const TNumber &);
friend TNumber operator * (const TNumber &, const TNumber &);
friend TNumber operator / (const TNumber &, const TNumber &);
friend TNumber operator % (const TNumber &, const TNumber &);

friend int operator == (const TNumber &, const TNumber &);
friend int operator != (const TNumber &, const TNumber &);
friend int operator < (const TNumber &, const TNumber &);
friend int operator <= (const TNumber &, const TNumber &);
friend int operator > (const TNumber &, const TNumber &);
friend int operator >= (const TNumber &, const TNumber &);

char* strrev(char *s) const;
friend TNumber abs(const TNumber &);
friend TNumber sqrt(const TNumber &);
friend TNumber pow(const TNumber &, const TNumber &);
friend double div(const TNumber &, const TNumber &);

friend ostream & operator << (ostream &, const TNumber &);
friend istream & operator >> (istream &, TNumber &);

friend TNumber rnd(const TNumber& from, const TNumber& to);
};

const TNumber zero = TNumber("0");
const TNumber one = TNumber("1");
const TNumber two = TNumber("2");

TNumber eae(TNumber u, TNumber v);

#endif

我哪里错了?

另外找到附加的c++ builder 6项目!

最佳答案

你是对的。 UnicodeString 是大多数字符串在 2010 年的默认设置。由于 Text 属性很可能是其中之一,因此编译的最安全方法是使用某些东西转换回来像下面这样:

TNumber n( AnsiString( Edit1->Text ).c_str() );

更新:

根据评论,我会澄清一下答案。答案是假设代码仍然只需要 ANSi 数据。否则,正如 David M. 指出的那样,更好的解决方案是更改底层 TNumber 类以处理 UnicodeString(即 wchar_t)。

关于c++ - 将 C++ builder 6 项目转换为 C++ builder 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4885453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com