码迷,mamicode.com
首页 > 编程语言 > 详细

托管C++中System::String^ 转换为 char*

时间:2019-08-15 21:15:52      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:堆内存   本机   str   内容   rop   namespace   tps   void   ring   

https://docs.microsoft.com/en-us/cpp/dotnet/how-to-convert-system-string-to-standard-string?view=vs-2019

StringToHGlobalAnsi方法可以把托管 String^对象的内容复制到本机堆,

然后将它转换为 (ANSI) 格式。此方法会分配所需的本机堆内存:

//using namespace System::Runtime::InteropServices;
char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(str);
printf(str2);
Marshal::FreeHGlobal( IntPtr(str2) );

 



托管C++中System::String^ 转换为 char*

标签:堆内存   本机   str   内容   rop   namespace   tps   void   ring   

原文地址:https://www.cnblogs.com/sinceret/p/11360330.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!