views:

88

answers:

2

I've been trying to figure out how to convert a string to a String in Visual Studio 2005 with no luck.

Here is the relevant code:

#include <string>
using namespace std;
#using <System.dll>
using namespace System;

string test = "a test string";

So I'm trying to convert test into a String^ to use inside other .NET classes, can anyone help me with this?

+2  A: 
String^ str = gcnew String(test)
Robert Fraser
Thanks, that works.
hora
A: 

should it not be String^ str = gcnew String(test.c_str());

anyone got a clue how to convert the other way????

Dan
No, the above answer worked for me. If you wanna go the other way around, check out this link: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.stringtohglobalansi.aspx
hora