467,080 Members | 960 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,080 developers. It's quick & easy.

incorrect result when converting from basic string to System::String

Hi,
I am using a c# library in my c++ project. so I have to convert a
basic string to System::string to make use of a function that takes
System::String as argument. I did it like this:

System::String^ s = gcnew System::String(basic_s.c_str()); //here
basic_s is a basic string in c++

But I found s contains less charactors than the original basic string,
some charactors are missing.
here, the basic string contians bytes that rang from -127 to 127,
which is the result of an encrypting function.

what's wrong with the converting? how to convert the string without
missing charactors?

Thanks!

Vivienne

Aug 20 '07 #1
  • viewed: 1482
Share:
1 Reply
Vivienne <zh**********@gmail.comwrote:
I am using a c# library in my c++ project. so I have to convert a
basic string to System::string to make use of a function that takes
System::String as argument. I did it like this:

System::String^ s = gcnew System::String(basic_s.c_str()); //here
basic_s is a basic string in c++

But I found s contains less charactors than the original basic string,
some charactors are missing.
here, the basic string contians bytes that rang from -127 to 127,
which is the result of an encrypting function.
And what do you expect the result to be? Which encoding to you expect
it to use?

As a general rule, it's a *really, really* bad idea to convert
arbitrary binary data (such as the result of encryption) to text
directly. Use Base64 instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 20 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joe | last post: by
4 posts views Thread by Yan Vinogradov | last post: by
3 posts views Thread by Andy Sutorius via DotNetMonster.com | last post: by
24 posts views Thread by Marcus Kwok | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.