Error: cannot convert from 'std::string' to 'System::String __gc*' [C++]
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 !!!!!!
Even though I've never used .NET I'm gonna try. Try this:
If it doesn't work we need the help of someone using .NET.
Greetz,
Illco
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);
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
std::string my_string = "Some text";
System::String* string = my_string.c_str();
should work :P
System::String* string = my_string.c_str();
should work :P
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement