在 Visual C++ .NET 中从 System::String* 转换为 Char*

来源:互联网 发布:笔记本电脑端口设置 编辑:程序博客网 时间:2024/04/27 15:09

转自 http://support.microsoft.com/kb/311259

 

使用的第二种方法

 

注意在头文件中#include <msclr/marshal.h>

 

另外 using namespace System::Runtime::InteropServices;

 

System::String * str = S"Hello world/n";
char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(str);
printf(str2);
Marshal::FreeHGlobal(str2);

 

第一种方法 说是  __pin 是老语法,需要在编译时加上一个选项,

故弃而不用。

 

第三种方法没有试。

 

 

原创粉丝点击