string与wstring互转

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
/// <summary>
///utf8转unicode
/// </summary>
bool Utf8ToUnicode( std::string& utf8_string, std::wstring& unicode_string)
{
    unicode_string = L"";
     )
    {
        return false;
    }

const char *temp_utf8_string = utf8_string.c_str();
    );
     == unicode_string_len )
    {
        return false;
    }

];
    memset(temp_unicode_string, ));
     == ::MultiByteToWideChar(CP_ACP, NULL, temp_utf8_string, strlen(temp_utf8_string), temp_unicode_string, unicode_string_len))
    {
        delete[] temp_unicode_string;
        temp_unicode_string = NULL;
        return false;
    }

unicode_string = temp_unicode_string;
    delete[] temp_unicode_string;
    temp_unicode_string = NULL;

return true;

}

/// <summary>
///unicode转utf-8
/// </summary>
bool UnicodeToUtf8( std::wstring& unicode_string, std::string& utf8_string)
{
    utf8_string = "";
     )
    {
        return false;
    }

DWORD utf8_string_len = WideCharToMultiByte(CP_ACP, , NULL, FALSE);// WideCharToMultiByte的运用
 == utf8_string_len)
    {
        return false;
    }
    ];
    memset(temp_utf8_string, ));
    , temp_utf8_string, utf8_string_len, NULL, FALSE))
    {
        delete[] temp_utf8_string;
        temp_utf8_string = NULL;
        return false;
    }

utf8_string = (std::string)temp_utf8_string;
    delete[] temp_utf8_string;
    temp_utf8_string = NULL;

return true;
}

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

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

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

  2. STL的string和wstring

    STL有字符串处理类——stirng和wstring,但是用的时候会觉得不是很方便,因为它不能像TCHAR一样根据定义的宏在char类型字符串和wchar_t进行转换,总不能因为程序要Unicode就 ...

  3. [C++]C++标准里 string和wstring

    typedef basic_string<char> string; typedef basic_string<wchar_t> wstring; 前者string是常用类型, ...

  4. c++ string 与 char 互转 以及base64

    c++ string 与 char 互转 很简单如下 ] = {'A','B','C','D','E'}; printf("%s\n",bts); //char to string ...

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

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

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

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

  7. string 到 wstring的转换

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

  8. How to convert string to wstring?

    How to convert string to wstring? - Codejie's C++ Space - C++博客     How to convert string to wstring ...

  9. 利用boost做string到wstring转换,以及字符集转换 - Error - C++博客

    利用boost做string到wstring转换,以及字符集转换 - Error - C++博客 利用boost做string到wstring转换,以及字符集转换 #include <boost ...

随机推荐

  1. <译>Zookeeper官方文档

    apache原文地址:http://zookeeper.apache.org/doc/trunk/zookeeperOver.html ZooKeeper ZooKeeper: A Distribut ...

  2. JavaMelody、prob系统监控工具使用配置

    分类: 工具 2014-04-23 14:41 1857人阅读 评论(1) 收藏 举报 目录(?)[+] 项 目开发结束了,需要做一下压力测试,就使用apache自带的ab程序进行压力测试,300个并 ...

  3. 【OpenGL基础篇】——使用面向对象方法封装OpenGL函数(二)

    今天封装了一个Line类.负责在昨天写的窗体上绘制线条. OpenGL画图是通过给glBegin函数设置參数达成的,绘制线条有三个不同的參数: GL_LINES : 绘制连接两个点的线段(绘制的端点位 ...

  4. 详解Android中那些酷炫返回方式的实现

    Android手机都会有返回键,不管是实体键,还是虚拟键.Android用户主要也都是通过这个返回键操控页面返回方式的,不比IOS逼格甚高的只保留一个操作键.这种方式是最普遍的返回方式,还有一种也是比 ...

  5. 建立第一个wcf程序

    使用管理员权限启动vs (否者将导致ServiceHost开启失败 权限不足) 1.创建一个空的控制台程序 2.添加程序集引用 System.ServiceModel 3.写入一些代码 如下 usin ...

  6. WebApi接口传参不再困惑(4):传参详解

    前言:还记得刚使用WebApi那会儿,被它的传参机制折腾了好久,查阅了半天资料.如今,使用WebApi也有段时间了,今天就记录下API接口传参的一些方式方法,算是一个笔记,也希望能帮初学者少走弯路.本 ...

  7. 已知的问题:本文总结了与Telerik UI for ASP.NET Core相关的所有已知问题。

    ASP.NET Core Framework 不支持数据表. 有关此限制的更多信息,请参阅dotnet / corefx#1039. 不支持本地化资源. 有关此限制的更多信息,请参阅dotnet / ...

  8. 优化数据页面(22)——n:n的数据关系

    设计要点:优化数据页面.界面设计.美化exce 阿金:那n::n就复杂了,你倒是想留有空间. 可是现实社会有时却不同意. 秀秀:唉.说的也是. 阿金:那怎么表达才合适啊? 秀秀:仅仅实用网格了. 阿金 ...

  9. atitit..国富论 在现代it企业项目管理中的作用attialx 总结---国富论读后感 attialx

    atitit..国富论 在现代it企业项目管理中的作用attialx 总结---国富论读后感 attialx 1. 国民财富的性质和原因的研究(简称:<国富论>) 1 2. 蕴含的重要管理 ...

  10. 使用 xlue 实现 tips

    经常遇到如下的需求 鼠标hover到目标对象一定时间后,弹出tips或者窗口; 鼠标离开目标对象一定时间后,隐藏tips或者窗口; 鼠标从目标对象移动到弹出的窗口上,这种状况下不隐藏窗口; 考虑到这种 ...