目前我正忙于从文本框中获取一些文本,然后将其转换为 const char*。我有以下代码:
System::String^ host = textBoxHostadres->Text;
const char* host2 = (const char*)(void*)Marshal::StringToHGlobalAnsi(host);
//system(host2); //What to do with this?
Marshal::FreeHGlobal(host2);
它在Marshal::FreeHGlobal
. 有人可以给我一个正确的方向来获取文本textbox
并将其传递给 aconst char*
吗?第一行运行良好,通过调试我看到文本被捕获。
更新:
System::String^ host = textBoxHostadres->Text;
pin_ptr<const wchar_t> wch = PtrToStringChars(host);
// Convert to a char*
size_t origsize = wcslen(wch) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
char nstring[newsize];
wcstombs_s(&convertedChars, nstring, origsize, wch, _TRUNCATE);
strcat_s(nstring, " (char *)");
const char* host2 = (const char*)(void*)Marshal::StringToHGlobalAnsi(host);
system(host2);
traceroute hostAddress(host2);