-
[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
", chr);
-
- //char to wchar_t
- wchar = (wchar_t *)malloc(sizeof(wchar_t) * 64);
- charTowchar(chr, wchar, sizeof(wchar_t) * 64);
-
- wprintf_s(L"%s
", wchar);//
- getchar();
-
- return 0;
- }
- Requirements: Ws2_32.lib
-
相关阅读:
四则运算出题器
四则运算出题网页
四则运算自动生成器实现(python、wxpython、GUI)
python 实现小学四则运算
Process and Thread States
COS AP-开启WPA后无法关联SSID!
WLC MAC Filtering
禅道--个人理解 简单介绍
IDEA解决乱码
avue 实现自定义列显隐并保存,并且搜索表单、form表单、crud列顺序互不影响。
-
原文地址:https://www.cnblogs.com/gredswsh/p/char_wchar_t.html
Copyright © 2020-2023
润新知