|
Sarah Rastkar,您好!
3x for your reply,but it seems your code does not
work
here is the code as your way:
Integer bbb; bbb.Randomize(GlobalRNG(),512); ostrstream
stream; char *p; stream << bbb <<
ends; int l= stream.pcount(); p =
(char*)malloc(stream.pcount()); p=stream.str();
but it has error when compile:
error C2678: binary '<<' : no operator defined which takes a
left-hand operand of type 'class ostrstream' (or there is no acceptable
conversion) Error executing cl.exe.
======== 2003-09-20 12:54:00 您在来信中写道:
========
This may work:
ostrstream
stream; stream << AnInteger << ends;
return
stream.str();
----- Original Message -----
Sent: Saturday, 20 September,
2003 09:05 ?.?
Subject: how to use Class
Integer?
Now, I want to use Class Integer, I generate a 512bit
integer and want to transfer it to string or some other form that can
be easy to transfered; I use encode, decode functions to implement it;
but it seems doesn't work correctly;
below is my
code:
void main() { Integer *a; char * seed; seed
=NULL; byte b; std::string timeSeed; // generate a random
512bit Integer if (!seed) { timeSeed =
IntToString(time(NULL)); seed =
(char*)malloc(timeSeed.length()); strcpy(seed ,
timeSeed.c_str()); }
GlobalRNG().Put((const byte *)seed,
strlen(seed)); a = new
Integer(); a->Randomize(GlobalRNG(),512);
// print the
Integer value std::string str; char s[64]; int len =
a->ByteCount(); for(int i=0; i<len;i++) { b =
a->GetByte(i); sprintf(s,"%x",b); printf("%x",b); str +=
s; }
printf("\n");
byte *tmp;
tmp = (byte*)
malloc(len); a->Encode(tmp,len); //encode a to byte array
tmp
for(i=0; i<len;i++) //print
tmp { printf("%x",*tmp); tmp++; } printf("\n");
Integer
*x; x = new Integer(); x->Decode(tmp,len);
int
r=x->Compare(*a);
printf("compare = %i",r); //here r is
1
[EMAIL PROTECTED] 2003-09-20
|
= = = = = = = = = = = = = = = = = = = = = =
致 礼!
李晖
2003-09-20
|