博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TCHAR和CHAR类型的互转
阅读量:4562 次
发布时间:2019-06-08

本文共 1172 字,大约阅读时间需要 3 分钟。

http://blog.csdn.net/ahjxly/article/details/8494217

http://blog.csdn.net/b_h_l/article/details/7581519

http://blog.chinaunix.net/uid-339069-id-3402668.html

没有定义UNICODE,所以它里面的字符串就是简单用" "就行了,创建工程的时候包含了UNICODE定义,就必须对TCHAR和char进行转换。

void TcharToChar(const TCHAR * tchar, char * _char){    int iLength;    //获取字节长度       iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);    //将tchar值赋给_char        WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);}void CharToTchar(const char * _char, TCHAR * tchar){    int iLength;    iLength = MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, NULL, 0);    MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, tchar, iLength);}

表明 TCHAR 与 WCHAR 属同一类型

char szA[100];                    // ANSI string buffer
WCHAR szW[100];            // Unicode string buffer
// Normal sprintf:all strings are ANSI
sprintf(szA, "%s","ANSI Str");
// Converts Unicode string to ANSI
sprintf(szA,"%S",L"Unicode Str");
// Normal swprintf:all strings are Unicode
swprintf(szW,L"%s",L"Unicode Str");
// Converts ANSI string to Unicode
swprintf(szW,L"%S", "ANSI Str");
注意:大写S 和小写s 的使用

 

 

转载于:https://www.cnblogs.com/yuguangyuan/p/5955959.html

你可能感兴趣的文章
day42
查看>>
jquery操作select(增加,删除,清空)
查看>>
Sublimetext3安装Emmet插件步骤
查看>>
MySQL配置参数
查看>>
全面理解Java内存模型
查看>>
A - Mike and palindrome
查看>>
DOTween教程
查看>>
java web中java和python混合使用
查看>>
创建学员类和教员类
查看>>
Cookie和Session的作用和工作原理
查看>>
字符串操作
查看>>
Visual Studio中改变environment 的布局和显示风格
查看>>
2016-XCTF Final-Richman
查看>>
文件下载
查看>>
extjs grid renderer用法
查看>>
vue 如何在循环中绑定v-model
查看>>
shell脚本
查看>>
[代码笔记]JS保持函数单一职责,灵活组合
查看>>
cmd 重定向
查看>>
【IOS开发】如何画1像素的线
查看>>