为什么不能将TCHAR *转换为char * [英] Why can't convert TCHAR* to char*

查看:339
本文介绍了为什么不能将TCHAR *转换为char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误C2664:'strcpy':无法将参数1从'TCHAR *'转换为'char *'
代码:

error C2664: 'strcpy' : cannot convert parameter 1 from 'TCHAR *' to 'char *' code:

LPCTSTR name, DWORD value
strcpy (&this->valueName[0], name);

错误C2664:'strlen':无法将参数1从'LPCTSTR'转换为'const char *'

error C2664: 'strlen' : cannot convert parameter 1 from 'LPCTSTR' to 'const char *'

LPCTSTR name; 
strlen (name)     

上面的代码可以在另一个项目中正常工作,我找不到为什么它不工作在这个MS VS2010项目的原因。

The code above to a class which works fine in another project, I can't find the reason why it doesn't work in this MS VS2010 Project.

推荐答案

例如定义_UNICODE时的 wcstombs 。或者只需使用 _tcslen (查看 Generic-文本例程映射)在TCHAR字符串上,编译器会将其传输到strlen或wcslen,取决于您是否使用unicode。

You need to use a function such as wcstombs when _UNICODE is defined. Either that or just use _tcslen (Look under Generic-Text Routine Mappings) on the TCHAR string and the compiler will transfer it to either strlen or wcslen depending if you are using unicode or not.

这篇关于为什么不能将TCHAR *转换为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆