惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
IT之家
IT之家
B
Blog
博客园_首页
博客园 - 司徒正美
有赞技术团队
有赞技术团队
博客园 - 聂微东
I
InfoQ
美团技术团队
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog

博客园 - double64

C# 遍历删除空文件夹 MFC 单文档无边框最大化全屏 MFC 单文档去掉菜单栏 MFC 对话框去边框最大化全屏 C++ 动态数组 C++ 安全的拷贝赋值(Copy-and-Swap 惯用法) C++ 基类派生类的 static_cast 和 dynamic_cast 转换的简单测试 visual studio 的 snippet 代码片段模板样式 Windows 右键管理官方小程序Autoruns C++ 结合 enum 按位与或组合检测枚举项 std::unique_ptr 当删除器类型为 无状态的时构造可以不用传删除器示例 两个用来写 CLI - Command-Line Interface 的命令解析库 enum class 类型转换 int 微软输入法中如何输出当前时间 音程知识 C++ 模板引用参数的各种情况 英语 12 种时态 Qt 手动添加 Q_OBJECT 需要添加的地方 C# WPF 绑定 ObservableObject 实现 INotifyPropertyChanged 接口 C++ 标准库 copy_if C++ lambda 和 bind 何时优先使用 Windows 下的 Qt 中 min max 函数冲突 C++ RVO 或 NRVO 可能触发的条件 C++ std::unique_ptr 和 std::shared_ptr 都支持自定义删除器(deleter) C++ 智能指针和动态数组 std::vector 插入另一个 vector 的范围元素 Qt tableWidget QTableWidget 常用一些属性设置 C++ 内部类(嵌套类)是可以访问外部类的私有保护成员的 C++ 宏展开顺序 C++ std::round() 四舍五入
C# 字符串转换
double64 · 2026-09-08 · via 博客园 - double64

字符串转换:

#include <msclr/marshal_cppstd.h>
using namespace msclr::interop;

// 从 std::string 转为 System::String^
std::string nativeStr = "Hello";
String^ managedStr = marshal_as<String^>(nativeStr);

// 从 System::String^ 转为 std::string
String^ managedMsg = "World";
std::string nativeMsg = marshal_as<std::string>(managedMsg);
#include <msclr/marshal_cppstd.h>
using namespace msclr::interop;

// String^ -> const char*
String^ managedStr = "Hello World";
std::string nativeStr = marshal_as<std::string>(managedStr);
const char* pChar = nativeStr.c_str();  // 注意:这个指针只在 nativeStr 生命周期内有效

// const char* -> String^
const char* pNative = "Hello from native";
String^ managedResult = marshal_as<String^>(pNative);