char*与System::String^的相互转换
2015-11-18 12:19
351 查看
#include "stdafx.h"
using namespace System; //这个命名空间如果缺的话,IntPtr这个无法识别
int main(array<System::String ^> ^args)
{
char* ch1 = "this is chars ";
//将char*转换为System::String^
String^ str1= System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)ch1);
//System::String^转换为char*
char* ch2 = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str1);
Console::WriteLine(str1);
Console::WriteLine(ch2);
Console::ReadLine();
}
using namespace System; //这个命名空间如果缺的话,IntPtr这个无法识别
int main(array<System::String ^> ^args)
{
char* ch1 = "this is chars ";
//将char*转换为System::String^
String^ str1= System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)ch1);
//System::String^转换为char*
char* ch2 = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str1);
Console::WriteLine(str1);
Console::WriteLine(ch2);
Console::ReadLine();
}
相关文章推荐
- Unity Shader 剔除黑色背景
- MySQL:数据备份与还原
- MySQL:用户管理
- swift学习基础代码1
- php学习之连接数据库微型博客
- intent打开第三方应用
- MySQL:触发器
- [LeetCode] Additive Number 加法数
- OCP考点实战演练01-备份恢复篇
- sqlnet.ora configuration for toad
- MySQL:视图
- 父窗口和iframe子窗口之间相互传递参数和调用函数或方法
- STM32F103 与 STM32F207/407编程的区别自我总结
- ViewPage+Fragment的使用用法
- MySQL下常见的启动失败与备份失败问题的解决教程
- MySQL:存储过程和函数
- 数据驱动编程 游戏GM的实现
- Linux chmod命令修改文件与文件夹权限命令代码
- Oracle建立表空间、用户、授权
- MySQL:索引