Converting from System::String to std::string while keeping nulls.

G

Guest

Hi,
I am using Visual C++ in Visual Studio 2005 to create a Managed Wrapper
around some C++ LIBS. I've created some classes that contains a pointer to
the LIB classes and everthing seems to compile well.
The problem is getting a std::string from System::String and still
preserving the nulls. System::String is a base64 encoded string of a series
of bytes. When I convert it back to a string from base64 representation, the
NULLs inside the decoded string makes it smaller. Suppose the decoded string
is $BFGDHF\0GDFS, I get $BFGDHF and the NULL char is interpretted as
termination char. But I need to get a string with all the nulls and data.

thanks
 
C

Carl Daniel [VC++ MVP]

Abhimanyu Sirohi said:
Hi,
I am using Visual C++ in Visual Studio 2005 to create a Managed Wrapper
around some C++ LIBS. I've created some classes that contains a pointer to
the LIB classes and everthing seems to compile well.
The problem is getting a std::string from System::String and still
preserving the nulls. System::String is a base64 encoded string of a
series
of bytes. When I convert it back to a string from base64 representation,
the
NULLs inside the decoded string makes it smaller. Suppose the decoded
string
is $BFGDHF\0GDFS, I get $BFGDHF and the NULL char is interpretted as
termination char. But I need to get a string with all the nulls and data.

Use the std::string constructor that takes a pair of iterators rather than
the one that takes a (w)char*. You can supply pointers to the begining and
one-past-the-end of the buffer containing the decoded bytes as the
"iterators" for the constructor.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top