[VC]char 和 wchar_t相互转化
- #include <windows.h>
- #include <stdio.h>
- //function: charTowchar
- //purpose:char to WCHAR 、wchar_t、LPWSTR etc
- void charTowchar(const char *chr, wchar_t *wchar, int size)
- {
- MultiByteToWideChar( CP_ACP, 0, chr,
- strlen(chr)+1, wchar, size/sizeof(wchar[0]) );
- }
- //function: wcharTochar
- //purpose:WCHAR 、wchar_t、LPWSTR to char
- void wcharTochar(const wchar_t *wchar, char *chr, int length)
- {
- WideCharToMultiByte( CP_ACP, 0, wchar, -1,
- chr, length, NULL, NULL );
- }
- int main (void)
- {
- char chr[128];
- wchar_t *wchar = L"陈鸿钦";
- //wchar_t to char
- wcharTochar(wchar, chr, sizeof(chr));
- printf("char is %s\n", chr);
- //char to wchar_t
- wchar = (wchar_t *)malloc(sizeof(wchar_t) * 64);
- charTowchar(chr, wchar, sizeof(wchar_t) * 64);
- wprintf_s(L"%s\n", wchar);//
- getchar();
- return 0;
- }
- Requirements: Ws2_32.lib
[VC]char 和 wchar_t相互转化的更多相关文章
- char,wchar_t 长度
(测试环境:VC++6.0) char类型 wchar_t类型 类型大小(32位系统) 8位 16位 常量字符表示法 'A' L'A' 或 'A' 常量字符串表示法 'hello' L'hello' ...
- 17.Letter Combinations of a Phone Number (char* 和 string 相互转化)
leetcode 第17题 分析 char*和string相互转化 char*(或者char)转string 可以看看string的构造函数 default (1) string(); copy (2 ...
- char与TCHAR相互转化
char与TCHAR相互转化 char strUsr[10] = "Hello"; TCHAR Name[100]; #ifdef UNICODE MultiByteToWideC ...
- char 转wchar_t 及wchar_t转char
利用WideCharToMultiByte函数来转换,该函数映射一个unicode字符串到一个多字节字符串.通常适合于window平台上使用. #include <tchar.h> #in ...
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]
本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换
本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下: #ifndef USE_H_ ...
- char* 和 wchar_t* 如何互相转换
char* 和 wchar_t* 如何互相转换 C函数可以用 wcstombs - 将宽字符转换成多字符 WCHAR -> CHAR mbstowcs - 把多字符把转换成宽字符 C ...
- 自己写实现char TO wchar_t 的转换
wchar_t CharToWChart(char nChar){ wchar_t nR; nR=nChar+32*256; return nR;}//--------------- ...
- linux 下 Linux 下char转换为wchar_t 设置本地为utf-8编码 以及wchar 的输入输出
LInux下使用mbstowcs函数可以将char转化为wchar_t函数含义:convert a multibyte string to a wide char string说明: Th ...
随机推荐
- Coding-Job:从研发到生产的容器化融合实践
大家好,我是来自 CODING 的全栈开发工程师,我有幸在 CODING 参与了 Coding-Job 这个容器化的编排平台的研发.大家对 CODING 可能比较了解, Coding.net 是一个一 ...
- spring-boot-starter-data-redis学习笔记01
1.Redis在Unbuntu14开启, 进入安装的src目录: 1.修改redis.conf,因为redis默认是受保护模式. protected-mode yes (改为no) bind 12 ...
- Dev Envirenment - Windows 10 && Visual Studio 2019 && OpenCV 4.1.0
当每天用着 C# && Winform && VS 2010 && .Net Framework 4.0 && Halcon & ...
- 352. Data Stream as Disjoint Intervals (TreeMap, lambda, heapq)
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- Python绘制正态分布曲线
使用Python绘制正态分布曲线,借助matplotlib绘图工具: \[ f(x) = \dfrac{1}{\sqrt{2\pi}\sigma}\exp(-\dfrac{(x-\mu)^2}{2 ...
- ue4 动画相关方法杂记
加载资源文件中的 骨骼,动画,蒙太奇----------------------------------------- FName anis("/Game/FirstPerson/Anima ...
- cf791B(完全图&dfs)
题目链接:http://codeforces.com/contest/791/problem/B 题意:给出一个无向图,问是否满足若存在边ab, bc则存在边ac: 思路:题意即,对于一个点,其所有子 ...
- 洛谷P2289 [HNOI2004]邮递员(插头dp)
传送门 太神仙了……讲不来讲不来->这里 //minamoto #include<iostream> #include<cstdio> #include<cstri ...
- 洛谷P2292 [HNOI2004]L语言
传送门 建好trie树 当$dp[j]==1$当且仅当存在$dp[k]=1$且$T[k+1,j]==word[i]$ 然后乱搞就行了 //minamoto #include<iostream&g ...
- VMWare虚拟机Windows下的下载与安装
原文链接:http://www.studyshare.cn/blog-front//software/details/1161/0一.下载此处收集各种开发工具软件,供下载官网下载:https://ww ...