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. VUE 方法

    1.$event 变量 $event 变量用于访问原生DOM事件. <!DOCTYPE html> <html lang="zh"> <head> ...

  2. JDBC:数据库操作:事务

    事务特征:原子性,一致性,独立性,持久性. 要想操作事务,必须按照以下步骤完成. 1,取消掉自动提交(SET AUTOCOMMIT=0):每次执行数据库更新的时候实际上发出SQL命令之后就已经提交上去 ...

  3. Docker Container同时启动多服务 supervisor

    Docker Container同时启动多服务 转载请注明来自:http://blog.csdn.net/wsscy2004 昨天踩了个天坑,我有一个基本的镜像centos6.5+ssh,是通过Doc ...

  4. Linux下如何修改root密码以及找回root密码

    Linux下修改root密码方法 以root身份登陆,执行: passwd 用户名 然后根据提示,输入新密码,再次输入新密码,系统会提示成功修改密码. 具体示例如下: [root@www ~]# pa ...

  5. 记一则Linux病毒的处理

    今天某项目经理反馈学校的某台服务器不停的向外发包,且CPU持续100%,远程登录后查看发现有一长度为10的随机字符串进程,kill掉,会重新生成另外长度为10的字符串进程.删除文件也会重复生成,非常痛 ...

  6. java 状态对象

    package cn.itcast.hibernate.sh.state; import org.hibernate.Session; import org.hibernate.Transaction ...

  7. cookie_session的详细用法

    相对路径与绝对路径 相对路径: 链接地址  <a href="list.do"></a> 表单提交地址 <form action="add. ...

  8. Linux常用指令总结

    概述 因为平时不是经常使用Linux系统,每次用到都需要重新温习一遍,这里对自己平时经常使用到的指令做个小结,方便后面直接查阅. 常用指令 登陆root指令 sudo su - 安装软件及卸载指令 d ...

  9. jms、amqp、mqtt区别与联系

    消息传递作为基本通信机制已经在全世界成功运用.无论是人与人.机器与人还是机器与机器之间,消息传递一直都是唯一常用的通信方式.在双方(或更多)之间交换消息有两种基本机制. 同步消息传递 异步消息传递 同 ...

  10. 转:BOOTSTRAP 增加、关闭、折叠TAB代码下载

    http://git.oschina.net/hbbcs/bootStrap-addTabs