2014-04-02工作日志:error C2440: 'initializing' : cannot convert from 'char [8]' to 'unsigned short *'
2014-04-02 09:49
501 查看
#include <stdio.h> #include <windows.h> #include <string.h> #include <tchar.h> void main() { DWORD dwCount; TCHAR *tC1="topStar"; TCHAR *tC2="TOPstar"; dwCount=_tcscmp(tC1,tC2); _tprintf("%d",dwCount); }
以上的写法明显是错误的,因为TCHAR变量所指的字符串没有经过TEXT转换。
因为字符串默认是以ASCII码方式保存,因为是英文字符,因此若以UNICODE 方式保存,就必须TEXT()转换成UNICODE格式。
以上代码有三个错误,以下的改变才是正确的:
#include <stdio.h> #include <windows.h> #include <string.h> #include <tchar.h> void main() { DWORD dwCount; TCHAR *tC1=TEXT("topStar"); TCHAR *tC2=TEXT("TOPstar"); dwCount=_tcsicmp(tC1,tC2); _tprintf(TEXT("%d"),dwCount); }
如果tC1是数组名,则也应该这样定义:
TCHAR tC1[]=TEXT("TOPstar");必须用TEXT()给转换一下。
相关文章推荐
- 报错 error C2664: 'CreateWindowExA' : cannot convert parameter 2 from 'unsigned short [10]' to 'const char *'
- error C2440: 'initializing' : cannot convert from 'unsigned long' to 'void *
- 轻松解决——error C2440: '=' : cannot convert from 'char [???]' to 'LPWSTR'
- error C2440: 'initializing' : cannot convert from 'boost::filesystem3::path' to 'std::basic_string<_
- error C2440: '=' : cannot convert from 'char [14]' to 'char [20]'
- error:cannot convert parameter 1 from 'unsigned char *' to 'char *'
- error C2440: '=' : cannot convert from 'char ** ' to 'char *** '
- string转Char*( error C2440: '=' : cannot convert from 'const char *' to 'char *')
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- 多线程问题cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *
- 使用atoi 报错:cannot convert parameter 1 from '_TCHAR *' to 'const char *'
- error C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'char *' to 'LPCTSTR'的解决方法
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- error C2440: '=' : cannot convert from 'void *' to 'float (*)[3]'
- CreateThread 函数常见错误 cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__st
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTrunkPage::* )(void)' to 'void (__thiscall CCmdTarget::* )(N
- error:MultiByteToWideChar cannot convert parameter 2 from 'char [10]' to 'unsigned short *'
- cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *
- 调用创建线程函数时出现'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned lo
- error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CchatDlg::* )(CPoint)' to 'UI