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. struts 在Action中访问web元素(request,session等)

    出发jsp: <?xml version="1.0" encoding="GB18030" ?> <%@ page language=&quo ...

  2. winfrom cahce 问题

    .Clear()不能随便用 .Clear()的比较没有什么意思,因为只是把DataTable清空而已,在堆中任然分配内存,一般要比较也是比较Close()方法,不过DataTable没有这个方法 至于 ...

  3. Bootstrap学习笔记面板(Panels)

    本文将讲解Bootstrap面板(Panels).面板组件用于把DOM组件插入到一个盒子中.创建一个基本的面板,只需要向div元素添加class .panel和 panel-default即可,如下面 ...

  4. T-sql for xml path使用

    用法: FOR XML PATH 方法是用于将查询结果集以XML形式展示 sql: p.ContactTypeID,p.ModifiedDate,p.Name from [Person].[Conta ...

  5. linux 常用的命令(转)

    常用指令 ls        显示文件或目录 -l           列出文件详细信息l(list) -a          列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir     ...

  6. Jekins部署.net站点

    前提 1.你需要一台windows服务 可以装vs的且有重启电脑权限的(具体vs版本根据你的团队决定) 2.下载jekins 安装包 地址:https://jenkins.io/download/   ...

  7. Oracle 动态sql 实现方式

    /******************************************************************* Sample Program 10: Dynamic SQL ...

  8. shared-service.ts

    shared-service.ts import { Observable } from 'rxjs/Observable'; import { Injectable } from '@angular ...

  9. SQL server账号无法登陆

  10. 由上而下层层剖析细说PCI+ExpresS+11新版精髓

    https://wenku.baidu.com/view/9a16c41fa300a6c30c229f87.html