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

推荐订阅源

WordPress大学
WordPress大学
A
About on SuperTechFans
量子位
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog
U
Unit 42
D
DataBreaches.Net
博客园 - Franky
D
Docker
宝玉的分享
宝玉的分享
Y
Y Combinator Blog
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Hugging Face - Blog
Hugging Face - 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);