最近做WinRT的项目,涉及到Platform::String^  和 std::string之间的转换,总结一下:

(1)先给出源代码:

std::wstring stows(std::string s)
{
std::wstring ws;
ws.assign(s.begin(), s.end());
return ws;
} Platform::String^ stops(std::string s)
{
return ref new Platform::String(stows(s).c_str());
} std::string wstos(std::wstring ws)
{
std::string s;
s.assign(ws.begin(), ws.end());
return s;
} std::string pstos(Platform::String^ ps)
{
return wstos(std::wstring(ps->Data()));
}

(2)画一个图更容易记忆:

  

std::string, std::wstring, wchar_t*, Platform::String^ 之间的相互转换的更多相关文章

  1. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...

  2. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下:    #ifndef USE_H_     ...

  3. wchar_t char string wstring 之间的转换

    wchar_t char string wstring 之间的转换 转:http://blog.csdn.net/lbd2008/article/details/8333583 在处理中文时有时需要进 ...

  4. 单独删除std::vector <std::vector<string> > 的所有元素

    下面为测试代码: 1.创建 std::vector< std::vector<string> > vc2; 2.初始化 std::vector<string> vc ...

  5. 没有与这些操作数匹配的 "<<" 运算符 操作数类型为: std::ostream << std::string

    错误显示:没有与这些操作数匹配的 "<<" 运算符       操作数类型为:  std::ostream << std::string 错误改正:要在头文 ...

  6. wchar_t,char,string,wstring等的总结

    一.LPSTR LPCSTR LPTSTR LPCTSTR等 确定的类型: LPSTR = CHAR * = char * LPCSTR = const CHAR * = char * //c意为co ...

  7. string与wstring之间的转换

    #include <string>std::string ws2s(const std::wstring& ws){    std::string curLocale = setl ...

  8. C++ string和wstring互转实现

    [转载] http://www.cppblog.com/kenwell/archive/2008/05/21/50661.html  很好,很强大,用到就是赚到! 代码如下: #include < ...

  9. c++ string 和wstring 之间的互相转换函数

    #include <string> std::string ws2s(const std::wstring& ws) { std::string curLocale = setlo ...

随机推荐

  1. bootstrap表单控件

    禁用状态: 被禁用的 fieldset 为<fieldset> 设置 disabled 属性,可以禁用 <fieldset> 中包含的所有控件. <form> &l ...

  2. centos下 KeyboardInterrupt 退不出来的结局方法

  3. P4592 [TJOI2018]异或 (可持久化Trie)

    [题目链接] https://www.luogu.org/problemnew/show/P4592 题目描述 现在有一颗以\(1\)为根节点的由\(n\)个节点组成的树,树上每个节点上都有一个权值\ ...

  4. FJOI2019划水记

    Day 0 和 $crk$ 神仙颓废 $crk$ 雀魂一位率 $40%$ $orz$,不知道的人怕不是以为开小号 晚上想早点睡觉,从 9 点躺到 12 点才睡着 Day 1 反正划水,心态良好,全写暴 ...

  5. python-使用字典使Fibonacci更有效率

    原代码: def fib(n): if n == 1: return 1 elif n == 2: return 2 else: return fib(n-1)+fib(n-2) 改进后: def f ...

  6. B - Toy Storage(POJ - 2398) 计算几何基础题,比TOYS多了个线段排序

    Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing ...

  7. PIE SDK屏幕坐标和地图坐标转换

    1. 功能简介 屏幕坐标和地图坐标转换,就是字面意思,将电脑屏幕的坐标转换为带有空间信息的地图坐标,主要运用PIE SDK地图控件的ToMapPoint()方法,而地图坐标转换为设备坐标(屏幕),用的 ...

  8. 发送请求时params和data的区别

    在使用axios时,注意到配置选项中包含params和data两者,以为他们是相同的,实则不然. 因为params是添加到url的请求字符串中的,用于get请求. 而data是添加到请求体(body) ...

  9. Java中的时间处理

    日期时间组件使用 java.util.Date:实现类,其对象具有时间.日期组件.java.util.Calendar:抽象类,其对象具有时间.日期组件.java.sql.Date:实现类,其对象具有 ...

  10. Spring混合配置时,遇到配置文件路径NotFound,使用PathMatchingResourcePatternResolver解决

    在将spring的xml配置改为java配置的过程中,遇到了一些问题,block时间比较长的一个问题是资源(.xml, .properties)的路径找不到,最后是使用PathMatchingReso ...