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. 算法笔记_097:蓝桥杯练习 算法提高 P1001(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 当两个比较大的整数相乘时,可能会出现数据溢出的情形.为避免溢出,可以采用字符串的方法来实现两个大数之间的乘法.具体来说,首先以字符串的形式输入两个整 ...

  2. Codeforces Round #105 D. Bag of mice 概率dp

    http://codeforces.com/contest/148/problem/D 题目意思是龙和公主轮流从袋子里抽老鼠.袋子里有白老师 W 仅仅.黑老师 D 仅仅.公主先抽,第一个抽出白老鼠的胜 ...

  3. Intellij IDEA 10.5 语言设置

    适应于:英文操作系统,但是语言和区域设置为中文的环境. Mac: /Applications/IntelliJ IDEA CE.app/Contents/bin/idea.vmoptions 增加 - ...

  4. Loadrunner socket协议lrs_receive函数接收到返回数据包 仍然等待服务器返回--解决

    前段时间在使用loadrunner socket协议发送数据包到到服务器,使用lrs_receive接收服务器应答数据包,已经接收到数据包,但LR仍然在等待服务器端返回,而且日志打印显示每次接收返回都 ...

  5. Latex中设置字体颜色

    在用Latex时,想要使用不同颜色来突出某些关键点,有以下三种方案: 1.组合red.green和blue的值合成我们想要的颜色 \usepackage{color} \textcolor[rgb]{ ...

  6. asp.net mvc easyui datagrid分页

    提到 asp.net mvc 中的分页,很多是在用aspnetpager,和easyui datagrid结合的分页却不多,本文介绍的是利用easyui 中默认的分页控件,实现asp.net mvc分 ...

  7. golang中使用mongodb的操作类以及如何封装

    mgo简介 mongodb官方没有关于go的mongodb的驱动,因此只能使用第三方驱动,mgo就是使用最多的一种. mgo(音mango)是MongoDB的Go语言驱动,它用基于Go语法的简单API ...

  8. public_brokers

    This page is an effort to list the publically-accessible MQTT brokers, often useful for testing and ...

  9. C++的多态例子

    1.多态的例子 题目: 某小型公司,主要有四类员工(Employee):经理(Manager).技术人员(Technician).销售经理(SalesManager)和推销员(SalesMan).现在 ...

  10. Spring jar 下载地址

    Spring jar 下载地址 http://repo.springsource.org/libs-release-local/org/springframework/spring/