作者:zzandyc
来源:CSDN
原文:https ://blog.csdn.net/zzandyc/article/details/77540056
版权声明:本文为博主原创文章,转载请附上博文链接!

std::string ws2s(const std::wstring &ws)
{
size_t i;
std::string curLocale = setlocale(LC_ALL, NULL);
setlocale(LC_ALL, "chs");
const wchar_t* _source = ws.c_str();
size_t _dsize = * ws.size() + ;
char* _dest = new char[_dsize];
memset(_dest, 0x0, _dsize);
wcstombs_s(&i, _dest, _dsize, _source, _dsize);
std::string result = _dest;
delete[] _dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
} std::wstring s2ws(const std::string &s)
{
size_t i;
std::string curLocale = setlocale(LC_ALL, NULL);
setlocale(LC_ALL, "chs");
const char* _source = s.c_str();
size_t _dsize = s.size() + ;
wchar_t* _dest = new wchar_t[_dsize];
wmemset(_dest, 0x0, _dsize);
mbstowcs_s(&i, _dest, _dsize, _source, _dsize);
std::wstring result = _dest;
delete[] _dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}

std::string与std::wstring互相转换的更多相关文章

  1. C++ MFC std::string转为 std::wstring

    std::string转为 std::wstring std::wstring UTF8_To_UTF16(const std::string& source) { unsigned long ...

  2. 对std::string和std::wstring区别的解释,807个赞同,有例子

    807down vote string? wstring? std::string is a basic_string templated on a char, and std::wstring on ...

  3. 如何使用 window api 转换字符集?(std::string与std::wstring的相互转换)

    //宽字符转多字节 std::string W2A(const std::wstring& utf8) { int buffSize = WideCharToMultiByte(CP_ACP, ...

  4. std::u32string conversion to/from std::string and std::u16string

    I need to convert between UTF-8, UTF-16 and UTF-32 for different API's/modules and since I know have ...

  5. std::string和ctime之间的转换

    int year, month, day, hour, minute, second; string strTime: sscanf(strTime.c_str(), "%d-%d-%d % ...

  6. std::string, std::wstring, wchar_t*, Platform::String^ 之间的相互转换

    最近做WinRT的项目,涉及到Platform::String^  和 std::string之间的转换,总结一下: (1)先给出源代码: std::wstring stows(std::string ...

  7. std::wstring std::string w2m m2w

    static std::wstring m2w(std::string ch, unsigned int CodePage = CP_ACP) { if (ch.empty())return L&qu ...

  8. string 到 wstring的转换

    string 到 wstring的转换_一景_新浪博客     string 到 wstring的转换    (2009-08-10 20:52:34)    转载▼    标签:    杂谈    ...

  9. string 与wstring 的转换

    std::wstring StringToWString(const std::string &str) { std::wstring wstr(str.length(),L' '); std ...

随机推荐

  1. 区分重载(overload),覆盖(Override)和隐藏(hide)

    重载overload,这个概念是大家熟知的.在同一可访问区内被声名的几个具有不同参数列的(参数的类型.个数.顺序不同)同名函数,程序会根据不同的参数列来确定具体调用哪个函数,这种机制就是重载.重载不关 ...

  2. 10、QT分析之WebKit

    该文章整理自 网易博客 http://blog.163.com/net_worm/blog/static/12770241920101831312381/ 转载请注明出处 WebKit是QT4新整合的 ...

  3. 接口、抽象类、泛型、hashMap

    看到hashMap的put方法的第一行代码就懵逼了 就不继续往下看了 用简单的代码还原第一行代码 TsInter.java 接口 为什么要使用接口,比如写文章一样,我先列个大纲 //interface ...

  4. 关于对最新HTML总结PPT讲稿的分享

    如果大家还记得HTML,那么2009年的时候可能当时还是HTML1.0时代,而国际化的标准才刚刚开始,对于TABLE表格的使用,还有就是一些常用的标签都是及为简单的,因为当时的代码都是接近于短码,所以 ...

  5. POJ1157 LITTLE SHOP OF FLOWERS DP

    题目 http://poj.org/problem?id=1157 题目大意 有f个花,k个瓶子,每一个花放每一个瓶子都有一个特定的美学值,问美学值最大是多少.注意,i号花不能出如今某大于i号花后面. ...

  6. iText操作PDF读取JPEG图片ArrayIndexOutOfBoundsException异常

    iText版本:itextpdf-5.5.1.jar 问题描述 读取本地JPEG图片文件的代码: com.itextpdf.text.Image image = com.itextpdf.text.I ...

  7. CentOS7环境RabbitMQ集群配置管理

    CentOS7系统内核版本:3.10.0-514.26.2.el7.x86_64 一.对应主机host地址(三台主机host文件要保持一致) 10.100.2.10 v01-app-rabbitmq0 ...

  8. alter system set events相关知识

    格式:alter system|session set events ‘[eventnumber|immediate] trace name eventname [forever] [, level ...

  9. table中td的内容换行。

    table设置样式: table-layout: fixed; td设置: word-wrap: break-word;

  10. C# 执行CMD命令的方法

    /// <summary> /// 执行CMD命令 /// </summary> /// <param name="str"></para ...