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
 
//窄字符转宽字符
void ConvertA2W(wchar_t* the_strw, char* the_str, int len)//注意:默认the_strw和the_str有足够长度的内存,大于len字符;
{
    TCHAR* old_locale = _tcsdup( _tsetlocale(LC_ALL,NULL) ); 
    setlocale(LC_ALL, ".936");
    size_t nSize = len + ;
    memset(the_strw, , sizeof(wchar_t)*len);

size_t i_tem;
    mbstowcs_s(&i_tem, the_strw, nSize, the_str, nSize);
    _tsetlocale( LC_ALL, old_locale );                  //还原语言区域的设置 
    free( old_locale );                                 //还原区域设定
}
//宽字符转窄字符
void ConvertW2A(wchar_t* the_strw, char* the_str, int len)//注意:默认the_strw和the_str有足够长度的内存,大于len字符;
{
    TCHAR* old_locale = _tcsdup( _tsetlocale(LC_ALL,NULL) ); 
    setlocale(LC_ALL, ".936");
    size_t nSize = len + ;
    memset(the_str, , sizeof(char)*len);

size_t i_tem;
    wcstombs_s(&i_tem, the_str, nSize, the_strw, nSize);
    _tsetlocale( LC_ALL, old_locale );                  //还原语言区域的设置 
    free( old_locale );                                 //还原区域设定
}

wchat_t与char互转的更多相关文章

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

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

  2. CString与char *互转总结

    1 前言 今天在网上看论坛,发现大家对CString与Char *互转各说一词,其实我发现提问者所说的情况与回答问题的人完全不是同一情况,这里做一总结. 首先大家得清楚一件事,一般在网上提出问题的人大 ...

  3. C++ TCHAR* 与char* 互转

    C++ TCHAR* 与char* 互转 在MSDN中有这么一段: Note: The ANSI code pages can be different on different computers, ...

  4. C#string与char互转

    string s = "asdf"; //字符转char char[] c = s.ToCharArray(); Console.WriteLine(s[]); //char转st ...

  5. QString和char*互转

    1. QString转为char * // QString转QByteArray QByteArray sr = strQ.toLocal8Bit(); int len = sr.length(); ...

  6. CString和char互转,十六进制的BYTE转CString

    CString转char: CString m_Readcard; char ReaderName[22]; strcpy((char*)&ReaderName,(LPCTSTR)m_Read ...

  7. 2、CString与string借助char *互转

    CString是MFC中的类,MFC前端界面中获得的字符串是CString类.标准C/C++库函数是不能直接对CString类型进行操作的. string是C++中的类. 安全性 CString &g ...

  8. String -- char[]互转

    1.String --> char[] String str = "abc"; char[] chs = str.toCharArray(); 2.char[] --> ...

  9. java乱码详解(java中byte与char的转换)

    转自:http://hi.baidu.com/%C6%F3%D2%B5%BC%D2%D4%B0/blog/item/825a4858d6248e8b810a181a.html   java byte与 ...

随机推荐

  1. iOS UITableView表视图滚动隐藏UINavigationController导航栏

    UITableView 继承于UIScrollView 所以UIScrollView 的代理方法相同适用于UITableView 中 隐藏导航栏的方法为: self.navigationControl ...

  2. MFC中获取各个窗口之间的句柄或者指针对象的方法

    MFC在非常多的对话框操作中,我们常常要用到在一个对话框中调用还有一个对话框的函数或变量.能够用例如以下方法来解决.    HWND hWnd=::FindWindow(NULL,_T("S ...

  3. Python-代码对象

    可调用的对象是python执行环境中最重要的部分,python语句,赋值,表达式,模块等,这些 对象只是构成可执行代码块的拼图的很少的一部分,而这些代码块被称为代码对象.   每个可调用的对象的核心都 ...

  4. poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分, dinic, isap

    poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 ...

  5. 联想E440问题:点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误

    笔记本:Levono E440   问题描述: 在控制面板中,点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误,如何解决? 即使在安装联想的驱动后,也没办法解决   解决步骤: 1. ...

  6. maven分开打包jar文件和依赖jar包和资源文件

    <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &l ...

  7. Android--&gt;Realm(数据库ORM)使用体验,lambda表达式

    Realm,为移动设备而生.替代 SQLite 和 Core Data. 非常庆幸,官方帮助文档有中文: https://realm.io/cn/docs/java/latest/ 尽管眼下最新的版本 ...

  8. FPGA学习(第8节)-Verilog设计电路的时序要点及时序仿真

    一个电路能跑到多少M的时钟呢? 这和电路的设计有密切联系(组合逻辑的延时),我们知道电路器件都是由一定延迟的,所以信号的仿真很重要.如果延迟时间大于时钟,就会导致时序违例,出现逻辑错误. 项目要求30 ...

  9. Http basic Auth 认证方式帮助类

    BasicAuthenticationUtil import java.io.IOException; import java.security.MessageDigest; import javax ...

  10. Go快速入门

    整理一些Go最基本的语法,旨在快速入门. 最简单的hello world package main import "fmt" func main() { fmt.Println(& ...