Error: cannot convert from 'std::string' to 'System::String __gc*' [C++]

Started by
4 comments, last by Codorke 18 years, 8 months ago
This is really getting to much for me !!! How can i do this conversion (see subject) ? I'm programming in Microsoft Visual Studio 2003 .NET Framework 1.1 (C++). maybe a lexical_cast< ... > but i dont know how. Can someone help me out please ? Thanks !!!!!!
Advertisement
Even though I've never used .NET I'm gonna try. Try this:
std::string sSomeString;System::string sSomeSlightlyDifferentString = System::String( sSomeString.c_str() );

If it doesn't work we need the help of someone using .NET.

Greetz,

Illco
I'm using it like you said but now i getting the error :
System::String can only create a __gc on the __gc_heap


My Code :

System::String* unencodedString = System::String(text.c_str()); --> Error
Byte encodedBytes[] = ascii->GetBytes(unencodedString);
IEnumerator* myEnum = encodedBytes->GetEnumerator();
while (myEnum->MoveNext())
Byte b = *__try_cast<Byte __gc*>(myEnum->Current);

// Decode bytes back to String*.
System::String* decodedString = ascii->GetString(encodedBytes);
If you're using managed C++ (which i suspect if you're using std::string) you will need to declare the System::String as __gc
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
std::string my_string = "Some text";
System::String* string = my_string.c_str();

should work :P
This is indeed working well.

Thanks all for the replies and help !!!

This topic is closed to new replies.

Advertisement