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. ZOJ 2604 Little Brackets DP

    DP: 边界条件:dp[0][j] = 1 递推公式:dp[i][j] = sum{dp[i-k][j] * dp[k-1][j-1] | 0<k≤i} i对括号深度不超过j的,能够唯一表示为( ...

  2. php抽象类和接口的异同【转】

    1. 相同点: (1)      两者都是抽象类,都不能实例化. (2)      interface 实现类及 abstract class 的子类都必须要实现已经声明的抽象方法. 2. 不同点: ...

  3. 【PHPmailer】发送邮件(以163邮箱为例)

    1.参考TP社区:http://www.thinkphp.cn/code/989.html 2.phpmailer.rar下载地址:http://www.thinkphp.cn/code/downlo ...

  4. linux sudo命令详解

    --sudo命令重启网卡 sudo service network restart http://bestchenwu.iteye.com/blog/1450292

  5. HDFS原理解析(整体架构,读写操作流程及源代码查看等)

    前言 HDFS 是一个能够面向大规模数据使用的.可进行扩展的文件存储与传递系统.是一种同意文件通过网络在多台主机上分享的文件系统,可让多机器上的多用户分享文件和存储空间.让实际上是通过网络来訪问文件的 ...

  6. FIFO、LRU、OPT页面调度算法及样例

    网上非常多介绍3种页面置换算法的样例和过程是不对的, 本文依据<操作系统概念>第七版对三种算法做介绍,并给出正确的样例以验证算法. 一.FIFO先进先出页面置换算法,创建一个FIFO队列来 ...

  7. leetcode——Lowest Common Ancestor of a Binary Tree

    题目 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. 思路 这一次 ...

  8. 点滴积累【SQL Server】---使用Kettle实时同步DB2数据到SQLserver

    效果: 描述: 此操作适用于单点登录的同步用户. 首先,使用kettle将DB2数据同步到SQL中,然后添加到windows的任务计划中.定时执行同步数据. 特殊说明:此工具涉及到公司版权,所以不方便 ...

  9. yum中查找程序由哪个包提供

    有时候知道程序的名称,却不知道由那个包提供,也就是说不知道安装那个包,可以使用这个命令. 我们由provides关键字可以使用. 举例:semanage是SELinux的一个管理工具,可是我使用:yu ...

  10. 调试JDK1.8源码的方法

    背景 在学习JDK源码的时候,免不了需要调试JDK的源码. 比如:想理解ConcurrentHashMap的put(K k, V v)方法,JDK自带的rt.jar文件是支持断点调试,但是却看不到变量 ...