There is cleaner syntax if you're using a recent version of .net
#include "stdafx.h"
#include <string>
#include <msclrmarshal_cppstd.h>
using namespace System;
int main(array<System::String ^> ^args)
{
System::String^ managedString = "test";
msclr::interop::marshal_context context;
std::string standardString = context.marshal_as<std::string>(managedString);
return 0;
}
This also gives you better clean-up in the face of exceptions.
There is an msdn article for various other conversions
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…