如何将System :: String转换为const char *?

如何将“String ^”转换为“const char *”?

String^ cr = ("netsh wlan set hostednetwork mode=allow ssid=" + this->txtSSID->Text + " key=" + this->txtPASS->Text); system(cr); 

错误:

 1 IntelliSense: argument of type "System::String ^" is incompatible with parameter of type "const char *" 

你可以使用msclr::interop::marshal_context类来做到这一点:

 #include <msclr/marshal.h> 

然后:

 String^ something = "something"; msclr::interop::marshal_context ctx; const char* converted = ctx.marshal_as<const char*>(something); system(converted); 

ctx超出范围时, converted的缓冲区将被释放。

但在你的情况下,调用一个等效的托pipeAPI会容易得多:

 System::Diagnostics::Process::Start("netsh", "the args");